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) ?
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}
         ]
       }
    ]
}
                        The $not operator does not invert a complex expression. You need to use $and or $or for complex expressions.
Using logic rules, we know that the following are identical:
    not ( A and B ) = not A or not B
Using the MongoDB query language, you would have:
db.collection.find({$or:[{"a":{"$ne":false}},{"b":{"$ne":"condition"}}]})
OR simplifying the double boolean:
db.collection.find({$or:[{"a":true},{"b":{"$ne":"condition"}}]})
Using the MongoDB aggregation framework, you would have:
db.collection.aggregate([{"$match":{$or:[{"a":{"$ne":false}},{"b":{"$ne":"condition"}}]}}])
OR again, simplified to:
db.collection.aggregate([{"$match":{$or:[{"a":true},{"b":{"$ne":"condition"}}]}}])
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With