MongoDB using NOT and AND together
Posted
by
Stankalank
on Stack Overflow
See other posts from Stack Overflow
or by Stankalank
Published on 2014-06-07T02:12:07Z
Indexed on
2014/06/07
3:26 UTC
Read the original article
Hit count: 126
I'm trying to negate an $and
clause with MongoDB and I'm getting a MongoError: invalid operator: $and
message back. Basically what I want to achieve is the following:
query = { $not: { $and: [{institution_type:'A'}, {type:'C'}] } }
Is this possible to express in a mongo query?
Here is a sample collection:
{ "institution_type" : "A", "type" : "C" }
{ "institution_type" : "A", "type" : "D" }
{ "institution_type" : "B", "type" : "C" }
{ "institution_type" : "B", "type" : "D" }
What I want to get back is the following:
{ "institution_type" : "A", "type" : "D" }
{ "institution_type" : "B", "type" : "C" }
{ "institution_type" : "B", "type" : "D" }
© Stack Overflow or respective owner