Reputation: 22916
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}
}
);
Following is mentioned there
Note : Do this query without using $and operator.
If it can be solved without $and operator, then is $and operator just for readability sake or there is any particular reason we should prefer to use $and operator?
Upvotes: 0
Views: 22
Reputation: 22964
$and operator just for readability sake
No,
When should $and operator should be skipped in MongoDB?
other than below cases
Same Field
, then only option to achieve is using and
Same Operator
If you have to perform A OR (B AND C)
, then you need to use $or
, $and
.
If you have to get all American cushiness
or abc cushiness
with grades score
or address coord
, you need to use $and, $or
And the link OP mentioned is an exercise, so you can achieve that with/without $and
.
Upvotes: 1