NAND operator

30 views
Skip to first unread message

Hylke Bron

unread,
May 28, 2013, 5:25:54 AM5/28/13
to mongoo...@googlegroups.com
Hello,
 
How can i create an query to simulate the NAND effect?
 
I have tried the following:
 
child.find({
 $not
: {
  $and
:[
   
{"id.grandParent": "3"},
   
{"id.parent" : "2"},
   
{"id.child" : "0"}
 
]
 
}
});

But this query says MongoError: invalid operator: $and.
 
What i am trying is to find all children, except that particular child that has this particular parent and this particular grandParent.
 
But i cant get it to work. With an NAND operator, it would be rather easy, but there is no nand operator, and i cant do not and.
Any ideas?

Hylke Bron

unread,
May 28, 2013, 6:04:24 AM5/28/13
to mongoo...@googlegroups.com
Oh, if found the solution for this problem,
 
The following query makes the NAND effect:
 
child.find({
 $or
:[
 
{"id.grandParent": {$ne: "3"}},
 
{"id.parent" : {$ne: "2"}},
 
{"id.child" : {$ne: "0"}}
 
]
});
 
So what im doing here is finding all children that has at least one of the 3 statements true.
 
Each statement will return true when its not equal to resp. 3, 2 or 0. So the only document that will return false (and thus be excluded) in this or statement will be documents that have all of them equal to 3, 2 and 0.
 
I hope someone else finds this NAND operator useful
 
Hylke Bron
Reply all
Reply to author
Forward
0 new messages