python - Filter with multiple criteria in Mongo -
in mongo (specifically pymongo), goal able exclude records not equal 1 of many values. in example, data not 504 or 400. know can exclude records not contain single value using:
foo = db.collection.find({ "data": { "$ne": 400 } }) and have tried:
foo = db.collection.find({ "data": { "$ne": 400 }, "data": { "$ne": 504 } }) and
foo = db.collection.find({ "data": { "$ne": 400, "$ne": 504 } }) ...but in both cases, appears last comparison takes place. still records data 400. how can write filters on both? in other words, how can perform "data not equal of following [...]"?
you looking $nin.
according documentation,
$ninselects documents where:
- the
fieldvalue not in specified array or- the
fieldnot exist.
try
foo = db.collection.find({ "data": { "$nin": [504, 400] }, })
Comments
Post a Comment