MongoDB — Logical Operators

🍃 MongoDB 7.0+ 🟢 Chapter 14 of 50 📂 Phase 03: CRUD Operations — Reading & Writing Data 📅 2026 Edition

Combine multiple search conditions using $and, $or, $not, and $nor logical query operators.

1Logical Operators Summary
  • $and: Joins query clauses with a logical AND (all conditions must be true).
  • $or: Joins query clauses with a logical OR (at least one condition must be true).
  • $not: Inverts the effect of a query expression.
  • $nor: Joins query clauses with a logical NOR (all conditions must fail).
2Practical Examples
$or Query Example
// Find users who are admins OR have score greater than 90
db.users.find({
  $or: [
    { role: "admin" },
    { score: { $gt: 90 } }
  ]
});
$and Query Example
// Explicit $and (required when applying multiple conditions to same field)
db.products.find({
  $and: [
    { price: { $gt: 10 } },
    { price: { $lt: 50 } }
  ]
});
OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on MongoDB 7.0+ Standards · Last updated August 2026