Quiz Entry - updated: 2026.06.20
How do you combine multiple conditions in a MongoDB query?
Nest conditions inside the $and` and `$or operators, each taking an array of sub-conditions that can be freely combined.
{
$or: [
{ $and: [
{ day: { $gt: new Date('2000-01-01') } },
{ name: { $ne: 'Bert' } }
]},
{ name: { $eq: 'Anna' } }
]
}
This selects documents where:
- (date > 2000-01-01 AND name != 'Bert') OR
- (name == 'Anna')