Code
mongodb
// Comparison operators
db.products.find({ price: { $gt: 100, $lte: 500 } });
db.products.find({ status: { $in: ["active", "pending"] } });
// Logical operators
db.products.find({
$and: [
{ price: { $gt: 100 } },
{ $or: [{ category: "books" }, { category: "music" }] }
]
});
// Array and element operators
db.posts.find({ tags: { $all: ["mongo", "db"] } });
db.posts.find({ "tags.0": "mongo" }); // first element
db.posts.find({ featured: { $exists: true } });
// Regex
db.users.find({ name: /^A/i });