mongodb如何使用nand运算符进行查询?

mongodb如何使用nand运算符进行查询?,mongodb,operators,Mongodb,Operators,我使用的是$match聚合。 我试过这个 $match : { $not: { 'A': false, 'B': 'condition' } } 但不像nand那样工作。它的工作原理不是A,也不是B。 如何使用Not(A和B)进行查询 在mongodb中,您可以使用可用的选项以其他方式进行思考 db.Collection.find({'arrary.a':{$exists:false},'arrary.b':{$exists

我使用的是$match聚合。 我试过这个

    $match : { 
      $not: {
      'A': false,
      'B': 'condition'
      } 
    } 
但不像nand那样工作。它的工作原理不是A,也不是B。
如何使用Not(A和B)进行查询

在mongodb中,您可以使用可用的选项以其他方式进行思考

db.Collection.find({'arrary.a':{$exists:false},'arrary.b':{$exists:false}})

希望这能帮助您……

$not运算符不会反转复杂表达式。 对于复杂表达式,需要使用$and或$or

使用逻辑规则,我们知道以下内容是相同的:

    not ( A and B ) = not A or not B
使用MongoDB查询语言,您可以:

db.collection.find({$or:[{"a":{"$ne":false}},{"b":{"$ne":"condition"}}]})

OR simplifying the double boolean:

db.collection.find({$or:[{"a":true},{"b":{"$ne":"condition"}}]})
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"}}]}}])
使用MongoDB聚合框架,您将拥有:

db.collection.find({$or:[{"a":{"$ne":false}},{"b":{"$ne":"condition"}}]})

OR simplifying the double boolean:

db.collection.find({$or:[{"a":true},{"b":{"$ne":"condition"}}]})
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"}}]}}])

这会给你带来结果

{
    $or: [
        {'a': { $ne: 1} },
        {'b': { $ne: 2} }
    ]
}
然而,在我的例子中,这个表达式并没有产生预期的结果,所以我尝试了这个方法-

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

使用mongoDB创建NAND有一个非常简单的技巧:

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

对不起,我听不懂。你能解释一下$exists角色是什么吗?这意味着它将生成那些没有字段A和B的文档。我的问题不是关于exists,而是匹配一个特定的值。所以你可以这样做db.inventory.find({A:{$ne:false},B:{$ne:condition})已为
NAND
逻辑运算符打开功能请求,请参阅,您可以仅使用$nor进行此操作。