$gt
The `$gt` operator retrieves documents where the value of a field is greater than a specified value.
Syntax
{ field: { $gt: value } }
Parameters
field
stringrequiredThe field in the document you want to compare
value
numberrequiredThe value that the field should be greater than
Examples
Retrieve stores with sales exceeding $35,000
To retrieve stores with over $35,000 in sales, run a query with $gt operator on the sales.totalSales field.
Query:
db.stores.find({
"sales.totalSales": { $gt: 35000 }
}, { name: 1, "sales.totalSales": 1 }, { limit: 1 })
Output:
[{ "_id": "2cf3f885-9962-4b67-a172-aa9039e9ae2f", "name": "First Up Consultants | Bed and Bath Center - South Amir", "sales": { "totalSales": 37701 } }]
Find a store with more than 12 full-time staff
To find a store with more than 12 full time staff, run a query with the $gt operator on the staff.totalStaff.fullTime field.
Query:
db.stores.find({
"staff.totalStaff.fullTime": { $gt: 12 }
}, { name: 1, "staff.totalStaff": 1 }, { limit: 1 })
Output:
[{ "_id": "2cf3f885-9962-4b67-a172-aa9039e9ae2f", "name": "First Up Consultants | Bed and Bath Center - South Amir", "staff": { "totalStaff": { "fullTime": 18, "partTime": 17 } } }]