Operators start with $:
- Comparison:
$gt,$gte,$lt,$lte,$ne,$in,$nin - Logical:
$and,$or,$not - Elements:
$exists; arrays:$all,$size; text:$regex
Comparison and logical operators.
✍️ 2 exercises in this lessonOperators start with $:
$gt, $gte, $lt, $lte, $ne, $in, $nin$and, $or, $not$exists; arrays: $all, $size; text: $regexMastering MongoDB Query Operators helps you write clean and reliable MongoDB code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
// Marks of 80 or more
db.students.find({ marks: { $gte: 80 } })
// From Lahore OR Karachi
db.students.find({ city: { $in: ["Lahore", "Karachi"] } })
// Name starts with "S"
db.students.find({ name: { $regex: "^S" } })
[ { name: 'Ali', marks: 81, ... }, { name: 'Sara', marks: 94, ... } ]
[ { name: 'Ali', ... }, { name: 'Sara', ... } ]
[ { name: 'Sara', ... } ]
Check what you learned in “MongoDB Query Operators”.
Find prices greater than 1000.
db.products.find({ price: { : 1000 } })
Which operator matches any value in a list?
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services