← All tutorials

GoCareerGo Tutorials

MongoDB Tutorial

Documents, collections, CRUD, aggregation, Atlas and driver connectivity.

$and and $or

Combine multiple query conditions — $and requires all to match, $or requires at least one.

db.users.find({ $and: [{ age: { $gt: 18 } }, { city: 'London' }] });
db.users.find({ $or: [{ status: 'active' }, { role: 'admin' }] });
Tip

Note that {a: 1, b: 2} is already an implicit AND — you only need $and for combining complex sub-expressions on the same field.