MongoDB — Comparison Operators

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

Learn how to filter data using MongoDB comparison operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, and $nin.

1Comparison Operators Syntax Reference
OperatorMeaningExample Code
$eqEqual todb.products.find({ price: { $eq: 99.99 } })
$neNot equal todb.users.find({ status: { $ne: "banned" } })
$gtGreater thandb.products.find({ price: { $gt: 100 } })
$gteGreater than or equaldb.users.find({ age: { $gte: 18 } })
$ltLess thandb.products.find({ price: { $lt: 50 } })
$lteLess than or equaldb.scores.find({ score: { $lte: 35 } })
$inMatches any value in arraydb.users.find({ role: { $in: ["admin", "editor"] } })
$ninMatches none of values in arraydb.users.find({ role: { $nin: ["guest", "blocked"] } })
2Combining Comparison Operators for Ranges
Range Query Example
// Find products with price between $50 and $200 (inclusive)
db.products.find({
  price: { $gte: 50, $lte: 200 }
});
OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on MongoDB 7.0+ Standards · Last updated August 2026