mongodb how to query with nand operator?

Viewed 2538

I'm using $match of aggregation. and I tried this.

    $match : { 
      $not: {
      'A': false,
      'B': 'condition'
      } 
    } 

but not work like nand. it works like not A and not B. How can I query with Not(A and B) ?

4 Answers

This should fetch you the results

{
    $or: [
        {'a': { $ne: 1} },
        {'b': { $ne: 2} }
    ]
}

However, this expression did not yield the desired result in my case so I tried this-

{
     $nor: [
       {
         $and: [
             {a: 1},
             {b: 2}
         ]
       }
    ]
}

there is a very simple trick to create NAND with mongoDB:

$nor : { $and [..., ...] }
Related