</>
Skip to content
MongoDB lessons (15/38)

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

  1. Use equal operator
  2. Use range queries
  3. Use $in operator
  4. 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.