MongoDB — Find
Basic Find
db.users.find()
db.users.find({ name: "John" })
db.users.findOne({ name: "John" })
Comparison Operators
| Operator | Description |
|---|---|
| $eq | Equal |
| $ne | Not equal |
| $gt | Greater than |
| $gte | Greater or equal |
| $lt | Less than |
| $lte | Less or equal |
| $in | In array |
| $nin | Not in array |
Examples
// Greater than
db.users.find({ age: { $gt: 25 } })
// In array
db.users.find({ country: { $in: ["USA", "UK"] } })
// Range
db.users.find({ age: { $gte: 18, $lte: 30 } })
Projection
// Include fields
db.users.find({}, { name: 1, email: 1 })
// Exclude fields
db.users.find({}, { password: 0 })
Limit and Skip
db.users.find().limit(10)
db.users.find().skip(10).limit(10)
Sort
db.users.find().sort({ name: 1 }) // Ascending
db.users.find().sort({ name: -1 }) // Descending
Mini Practice
- Find all documents
- Find with conditions
- Use projection
- Sort and limit results
Up Next
Continue with Query — advanced queries.
Related Topics
Frequently Asked Questions about Find
What is Find in MongoDB?
Find 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 Find?
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 Find.
Why is Find important in MongoDB?
Find is essential for MongoDB development. Understanding this concept will help you write better code and solve real-world problems more effectively.