Combine filters explicitly with $and and $nor when readability matters; implicit AND is default for multiple top-level keys.
Implicit AND
db.orders.find({ status: 'open', total: { $gt: 100 } })
Explicit $and / $nor
db.orders.find({
$and: [
{ status: 'open' },
{ $or: [{ region: 'EU' }, { region: 'UK' }] }
]
})
db.orders.find({ status: { $nin: ['cancelled', 'void'] } })Practice: Use practice database in mongosh.
$in shorthand
db.orders.find({ status: { $in: ['open', 'pending'] } })
Important interview questions and answers
- Q: $nin caveat?
A: Still scans if no index—same as NOT IN SQL without index support. - Q: $nor?
A: Matches docs failing all expressions in array.
Self-check
- Rewrite status in open or pending with $in.
- When use explicit $and?
Tip: $nin still needs selective indexes on large collections.
Interview prep
- Implicit AND?
- Multiple top-level keys combine with AND.
- $nin?
- Not in listed values.