Comparison operators go inside the field's value: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin.
mongosh
db.products.find({ price: { $gte: 30, $lte: 100 } })
db.products.find({ category: { $in: ["office", "furniture"] } })
db.orders.find({ status: { $ne: "cancelled" } })Logical operators
$and, $or, $nor take arrays of conditions; $not negates one condition. Conditions on *different* fields are implicitly ANDed, so you only need $and when combining conditions on the *same* field.
mongosh
db.products.find({
$or: [
{ price: { $lt: 20 } },
{ rating: { $gte: 4.8 } }
]
})
// implicit AND
db.products.find({ category: "electronics", stock: { $gt: 50 } })