Open rochacbruno opened 7 years ago
Test case for future implementation
db.tags.insert({"tags":["red", "tall", "cheap"]});
db.tags.insert({"tags":["blue", "tall", "expensive"]});
db.tags.insert({"tags":["blue", "little", "cheap"]});
# find all blue
db.tags.find({tags: "blue"})
# find all blue and cheap
db.tags.find({ tags: { $all: ["cheap", "blue"] } } )
# find all not blue
db.tags.find({tags: { $ne: "blue" } })
# find all "blue" and "cheap" but not "red" and not "tall"
db.tags.find({ $and: [ {tags: { $all: ["blue", "cheap"] } }, { tags: { $nin: ["red", "tall"] } } ] })
I did a workaround saving a string version of my tags as {'tags_string': ',python,flask,other,another,'}
and querying with
col.find({'tags_string': {'$regex': '.*,python,.*'}})
@schapman1974 @jjonesAtMoog can you guys add hacktoberfest label to this issue please?
I have a document like this
It has a
'tags': ['python', 'flask', 'pythonplanet', 'pyplanet', 'new']
and I have more documents with tagpython
When I search using
{'tags': 'python'}
Ok that is expected so lets use
{'$in': 'python'}
or with a list:
{'$in': ['python', 'flask']}
I checked the source code and currently the
$in
operator only works in thereverse
way, it works currently to match a single field against an array of possibilities. But not to check an array against a single value or array.