Grokking MongoDB
0% completed
Logical Operators
How do you find the users who are younger than 25 or older than 35? One condition on age cannot say this, because no single value is both below 25 and above 35. You need two separate conditions and a rule for joining them, and that rule is a logical operator.
MongoDB has four logical operators.
| Operator | Returns a document when | Written as |
|---|---|---|
$or | At least one condition is true | { $or: [ {...}, {...} ] } |
$nor | No condition is true | { $nor: [ {...}, {...} ] } |
$and | Every condition is true | `{ $and: [ {.. |
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%