Logical Operators in MongoDB

From the MongoDB cheat sheet · Query Operators · verified Nov 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: $expr to compare fields with aggregation expressions
queryoperatorslogical

Continue with MongoDB

Save the full cheat sheet or work through every related task.

More MongoDB tasks

Back to the full MongoDB cheat sheet