Mongodb $match中的嵌套布尔查询

Mongodb $match中的嵌套布尔查询,mongodb,mongoose,mongodb-query,aggregation-framework,Mongodb,Mongoose,Mongodb Query,Aggregation Framework,我在文档中找不到对这个概念的引用,所以我想在这里问一下。我们正在使用一些布尔查询逻辑,我正在使用如下内容构建一个$match阶段: { '$match': { '$or': [ { depth: { '$or': [ { '$gt': 1 }, { '$lte': 36 }, { '$ne': 15 } ] } }, { height: { '$and': [ { '$gt': 1 }, { '$lte': 36 }, { '$ne': 15 } ] } } ] } }

我在文档中找不到对这个概念的引用,所以我想在这里问一下。我们正在使用一些布尔查询逻辑,我正在使用如下内容构建一个
$match
阶段:

{ '$match': 
 { '$or': 
    [ { depth: { '$or': [ { '$gt': 1 }, { '$lte': 36 }, { '$ne': 15 } ] } },
      { height: { '$and': [ { '$gt': 1 }, { '$lte': 36 }, { '$ne': 15 } ] } } ] } },
有人能确认是否支持这种类型的嵌套布尔逻辑吗

在我的测试中,它不会返回任何结果,但也不会引发任何异常


谢谢

正确的语法应该是

{$match: {
    $and: [
        {depth: {$gt: 1}},
        {depth: {$lte: 36}},
        {depth: {$ne: 15}},
        {height: {$ne: 15}},
        .... etc ....
    ]
}}
尽管有一种更简单的查询方式

{$match: {
    depth: {$gt: 1, $lte: 36, $ne: 15},
    height: {$gt: 1, $lte: 36, $ne: 15}
}}
更新

这是您的查询后更新

{$match: {
    $or: [
        {depth: {$gt: 1}},
        {depth: {$lte: 36}},
        {depth: {$ne: 15}},
        {height: {$gt: 1, $lte: 36, $ne: 15}} 
    ]
}}

正确的语法应该是

{$match: {
    $and: [
        {depth: {$gt: 1}},
        {depth: {$lte: 36}},
        {depth: {$ne: 15}},
        {height: {$ne: 15}},
        .... etc ....
    ]
}}
尽管有一种更简单的查询方式

{$match: {
    depth: {$gt: 1, $lte: 36, $ne: 15},
    height: {$gt: 1, $lte: 36, $ne: 15}
}}
更新

这是您的查询后更新

{$match: {
    $or: [
        {depth: {$gt: 1}},
        {depth: {$lte: 36}},
        {depth: {$ne: 15}},
        {height: {$gt: 1, $lte: 36, $ne: 15}} 
    ]
}}

谢谢你的回复。然而,我认为这并不能完全实现我的目标,因为我希望能够结合布尔。我更新了我的例子,希望能更好地说明我的需求。啊,这很有道理。谢谢你的澄清!将此标记为已接受答案。感谢您的回复。然而,我认为这并不能完全实现我的目标,因为我希望能够结合布尔。我更新了我的例子,希望能更好地说明我的需求。啊,这很有道理。谢谢你的澄清!将此标记为已接受的答案。