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,

$nin selects documents where:

  • the field value not in specified array or
  • the field not exist.

try

foo = db.collection.find({     "data": { "$nin": [504, 400] }, }) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -