Re: "" operator (and C++ driver)

From: Asya Kamsky <asya@xxxxxxxxxxx>
To: mongodb-user <mongodb-user@xxxxxxxxxxxxxxxx>
Date: Fri, 15 Apr 2016 10:38:00 -0400
Why ads?
Do you mean the $nor
<https://docs.mongodb.org/manual/reference/operator/query/nor/> operator?


On Fri, Apr 15, 2016 at 10:13 AM, Szaniszlo Szöke <szoke.szaniszlo@xxxxxxxxx
wrote:

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("&not" << obj12);

Thanks in advance for any help.

--
You received this message because you are subscribed to the Google Groups
"mongodb-user"
group.

For other MongoDB technical support options, see:
https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google Groups
"mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/cf7b6523-8cf8-49fd-ad38-0ec84d4004e5%40googlegroups.com
<https://groups.google.com/d/msgid/mongodb-user/cf7b6523-8cf8-49fd-ad38-0ec84d4004e5%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.




-- 
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
Free MongoDB Monitoring - cloud.mongodb.com
Free Online Education - university.mongodb.com
Get Involved - mongodb.org/community
We're Hiring! - https://www.mongodb.com/careers

-- 
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
--- 
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAOe6dJDmpY02JnWPXSZo0ozZvovfXF49CHABqivE6i7FEV6p5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Why ads?