Comparison, logical, and array operators. Projection, sort, skip, and limit.
Queries and Operators is one of the most important topics in MongoDB in 5 Days. This lesson builds the foundation you need before moving to more advanced concepts — take time with each example and run the code yourself.
// Numeric comparisons
db.products.find({ price: { $gt: 100 } }) // > 100
db.products.find({ price: { $gte: 100 } }) // >= 100
db.products.find({ price: { $lt: 50 } }) // < 50
db.products.find({ price: { $ne: 0 } }) // != 0
db.products.find({ category: { $in: ['Electronics', 'Books'] } })
db.products.find({ category: { $nin: ['Food'] } }) // AND (implicit — just combine conditions)
db.products.find({ price: { $lt: 100 }, inStock: true })
// Explicit AND
db.products.find({ $and: [ { price: { $lt: 100 } }, { category: 'Electronics' }
]})
// OR
db.products.find({ $or: [ { price: { $lt: 10 } }, { featured: true }
]})
// NOT
db.products.find({ category: { $not: { $eq: 'Food' } } }) // Projection: 1 = include, 0 = exclude
db.products.find({}, { name: 1, price: 1, _id: 0 })
// Sort: 1 = ascending, -1 = descending
db.products.find().sort({ price: -1 })
// Pagination
const PAGE = 2;
const PER_PAGE = 10;
db.products.find() .sort({ createdAt: -1 }) .skip((PAGE - 1) * PER_PAGE) .limit(PER_PAGE) Before moving on, make sure you can answer these without looking: