This seems like a pretty simple question, but I didn’t find the answer: I use MongoDB and I want to fulfill a query in which I provide search criteria, but I also want to highlight an exception when certain documents are excluded based on the criteria. For example, imagine a collection with the name , age and gender fields.
Getting everyone below a certain age? Easy: <collection>.find({'age':{'$lt':<maxAge>}}) Getting all women below a certain age? A piece of cake: <collection>.find({'gender':female, 'age':{'$lt':<maxAge>}})
But what about extracting everyone except when they are [women and below a certain age?]. You can easily undo a specific field using the $ ne operator, but how do I deny anyone who matches a set of criteria?
J-bob source share