Filter with multiple criteria in Mongo
In Mongo (specifically pymongo), my goal is to be able to exclude records
which are not equal to one of many values. In this example, where the data
is not 504 or 400. I know that I can exclude records which do not contain
a single value using:
foo = db.collection.find({
"data": { "$ne": 400 }
})
And I 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, it appears that only the last comparison takes
place. I still get records where data is 400. How can I write this so that
it filters on both? In other words, how can I perform a "data is not equal
to any of the following [...]"?
No comments:
Post a Comment