$gte
The `$gte` operator retrieves documents where the value of a field is greater than or equal to a specified value.
Syntax
{ field: { $gte: <value> } }
Parameters
field
stringrequiredThe field in the document you want to compare
value
numberrequiredThe value that the field should be greater than or equal to
Examples
Find stores with sales >= $35,000
To retrieve stores with at least $35,000 in sales, run a query using the $gte operator on the sales.totalSales field.
Query:
db.stores.find({
"sales.totalSales": { $gte: 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 promotion events with discount >= 15%
To find stores with promotions with a discount of at least 15% for laptops, run a query using the $gte operator.
Query:
db.stores.find({
"promotionEvents.discounts": {
$elemMatch: {
categoryName: "Laptops",
discountPercentage: { $gte: 15 }
}
}
}, { name: 1 }, { limit: 2 })
Output:
[
{ "_id": "60e43617-8d99-4817-b1d6-614b4a55c71e", "name": "Wide World Importers | Electronics Emporium - North Ayanashire" },
{ "_id": "3c441d5a-c9ad-47f4-9abc-ac269ded44ff", "name": "Contoso, Ltd. | Electronics Corner - New Kiera" }
]