I’m trying to do something like this :
select * from table where not (a=3 and b=4 and c=3 or x=4)
I would expect this to work:
db.table.find({
$not: {
$or: [
{
$and: [
{ a: 3 },
{ b: 4 },
{ c: 3 }
]
},
{ x: 4 }
]
}
})
But it gives me an error:
error: { "$err" : "invalid operator: $and", "code" : 10068 }
Is there another way to express it in mongodb?
Using
{ $not : { $and : []} }will not work ($notis not like other operators, can only be applied to negate the check of other operators).$and is not the problem here, this also doesn’t work (though without reporting any errors):
you’d have to rewrite it to
Coming back to your query:
is equivalent to:
and that you can do in mongo: