Beyond equality: comparison ($gt, $lte), logical ($and, $or), element ($exists), and array operators.
Comparison and logical
db.products.find({
price: { $gte: 10, $lte: 50 },
$or: [{ tags: 'sale' }, { category: 'clearance' }]
})Practice: Use practice database in mongosh.
Exists and type
db.products.find({ discontinuedAt: { $exists: false } })
db.products.find({ price: { $type: 'double' } })
Important interview questions and answers
- Q: $or placement?
A: Can be top-level or inside field expressions—mind precedence. - Q: $exists false?
A: Matches docs where field is missing or null depending on other filters.
Self-check
- Filter price between 10 and 50.
- Find docs without discontinuedAt.
Tip: Preview destructive filters with find before updateMany/deleteMany.
Interview prep
- $gte?
- Greater than or equal comparison on field.
- $exists?
- Tests field presence.