Logical Operators in MongoDB

From the MongoDB cheat sheet · Query Operators · verified Jul 2026

Logical Operators

Combine multiple query conditions

javascript
// AND - all conditions must match
db.users.find({
  $and: [
    { age: { $gte: 18 } },
    { status: "active" },
    { emailVerified: true }
  ]
})

// OR - any condition can match
db.products.find({
  $or: [
    { category: "sale" },
    { price: { $lt: 20 } },
    { featured: true }
  ]
})

// NOT - invert condition
db.users.find({
  status: { $not: { $eq: "banned" } }
})

// NOR - none of the conditions
db.products.find({
  $nor: [
    { discontinued: true },
    { stock: 0 }
  ]
})
💡 Implicit AND when listing multiple fields
📌 $or requires array of conditions
⚡ $nor useful for exclusion logic
⚠️ Complex logic can impact performance
🔗 Related: $where for JavaScript expressions
queryoperatorslogical

More MongoDB tasks

Back to the full MongoDB cheat sheet