MongoDB — Comparison Operators
Equal
db.users.find({ name: "John" })
db.users.find({ name: { $eq: "John" } })
Not Equal
db.users.find({ name: { $ne: "John" } })
Greater Than
db.users.find({ age: { $gt: 25 } })
Greater or Equal
db.users.find({ age: { $gte: 25 } })
Less Than
db.users.find({ age: { $lt: 30 } })
Less or Equal
db.users.find({ age: { $lte: 30 } })
In
db.users.find({ country: { $in: ["USA", "UK", "Canada"] } })
Not In
db.users.find({ country: { $nin: ["USA", "UK"] } })
Mini Practice
- Use equal operator
- Use range queries
- Use $in operator
- Combine operators
Up Next
Continue with Logical Operators — logical operators.
Related Topics
Frequently Asked Questions about Comparison Operators
What is Comparison Operators in MongoDB?
Comparison Operators is a fundamental concept in MongoDB. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Comparison Operators?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Comparison Operators.
Why is Comparison Operators important in MongoDB?
Comparison Operators is essential for MongoDB development. Understanding this concept will help you write better code and solve real-world problems more effectively.