https://www.w3resource.com/mongodb-exercises/mongodb-exercise-12.php
db.restaurants.find(
{
"cuisine" : {$ne : "American "},
"grades.score" :{$gt: 70},
"address.coord" : {$lt : -65.754168}
}
);
以下是
Note : Do this query without using $and operator.
如果它可以在没有$和运算符的情况下解决,那么$和运算符只是为了可读性,还是有任何特殊的原因我们应该更喜欢使用$和运算符?
$和运算符只是为了可读性
否,
在MongoDB中什么时候应该跳过$和运算符?
other than below cases
- 具有多个表达式的查询指定
Same Field
,则唯一要实现的选项是使用and
- 具有指定
Same Operator
的多个表达式的查询
参考
如果必须执行A OR (B AND C)
,则需要使用$or
、$and
。
如果必须使用grades score
或address coord
获取所有American cushiness
或abc cushiness
,则需要使用$and, $or
上面提到的链接OP是一个练习,所以你可以在有/没有$and
的情况下实现它。