Hi everyone,
I'm trying to get the opposite of a complex search using $not.
Let's take a very simple case.
Searching for: (_id == 5) || (_id == 9) is done with command:
{ $or: [{_id: 5}, {_id: 9}]}
I expected to find the opposite by writing:
{$not: { $or: [{_id: 5}, {_id: 9}]}}
but that doesn't work, the correct syntax being:
{$and: [{_id: {$ne: 5}}, {_id: {$ne: 9}}]}
in other words: is there a way to reverse a query, like in SQL, by using a NOT command in front of it ?
Note: the real query I have to reverse is a mix of AND, OR, REGEX, etc. so I have no way to parse it and reverse it "by hand".
For those interested, the equivalent C++ code looks like:
mongo::BSONObj obj1 = BSON("_id" << BSON("$eq" << 5));
mongo::BSONObj obj2 = BSON("_id" << BSON("$eq" << 9));
mongo::BSONObj obj12 = mongo::OR(obj1, obj2);
// unfortunately, this doesn't work:
mongo::BSONObj obj = BSON("¬" << obj12);
Thanks in advance for any help.