3

我在此查询中使用了多个运算符。我没有收到任何语法错误,但我没有收到任何数据(而且应该是),所以我很确定我正在查看一个逻辑错误。问题是,我看不到。

询问:

db.questions.find(
    {'$and': [
        {'answers.s_user_id': {'$ne': s_user_id}},
        {'$or': [
                {'s_text': re.compile(s_term, re.IGNORECASE)},
                {'choices': re.compile(s_term, re.IGNORECASE)}
        ]}
    ]}
)

任何提示表示赞赏。

4

2 回答 2

6

我刚刚发现这里记录的问题:https ://jira.mongodb.org/browse/SERVER-2585

直到 2011 年 7 月 24 日的 MongoDB 1.9.1 才支持嵌套的 $OR。我在旧版本上。

于 2011-08-09T18:38:09.750 回答
0
Please find the query
AND Queries With Multiple Expressions Specifying the Same Operator

Consider the following example:

db.inventory.find( {
    $and : [
        { $or : [ { price : 0.99 }, { price : 1.99 } ] },
        { $or : [ { sale : true }, { qty : { $lt : 20 } } ] }
    ]
} )
于 2014-07-03T13:02:32.273 回答