1. Which operator is used to find documents where a field value is greater than a specified value?
The dollar gt operator stands for greater than and is used to find documents where a field value is greater than a specified value. For example, to find all users older than 25, you would use age dollar gt 25. MongoDB provides several comparison operators: dollar gt for greater than, dollar gte for greater than or equal to, dollar lt for less than, dollar lte for less than or equal to, dollar eq for equal to, and dollar ne for not equal to. These operators are essential for filtering documents based on numeric or date comparisons.
// Find users older than 25
db.users.find({ age: { $gt: 25 } })
// Find products with price greater than 100
db.products.find({ price: { $gt: 100 } })
// Combine with other operators
db.users.find({ age: { $gt: 25, $lt: 40 } })