Definition
$gte$gteselects documents where the value of the specified field is greater than or equal (>=) to the specified value.For most data types, comparison operators only perform comparisons on fields where the BSON type matches the query value's type. MongoDB supports limited cross-BSON comparison through Type Bracketing.
Compatibility
You can use $gte for deployments hosted in the following
environments:
MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Syntax
The $gte operator has the following form:
{ field: { $gte: value } }
Examples
The examples on this page use data from the sample_mflix sample dataset. For details on how to load this dataset into your self-managed MongoDB deployment, see Load the sample dataset. If you made any modifications to the sample databases, you may need to drop and recreate the databases to run the examples on this page.
Match Document Fields
This example selects documents in the movies collection where
runtime is greater than or equal to 720 minutes:
db.movies.find( { "runtime": { $gte: 720 } }, { _id: 0, title: 1, runtime: 1, plot: 1 } )
[ { plot: 'The economic and cultural growth of Colorado spanning two centuries from the mid-1700s to the late-1970s.', runtime: 1256, title: 'Centennial' }, { plot: 'A dramatization of the missions and adventures of the greatest spy in British history.', runtime: 720, title: 'Reilly: Ace of Spies' }, { plot: "A 13-hour mini-series detailing James A. Michner's fictional account of the American space program from the years after World War II to the Apollo landings on the moon in the early 1970's.", runtime: 780, title: 'Space' }, { plot: 'A documentary on the history of the sport with major topics including Afro-American players, player/team owner relations and the resilience of the game.', runtime: 1140, title: 'Baseball' }, { plot: 'Taken spans five decades and four generations, centering on three families: the Keys, Crawfords, and Clarkes. World War II veteran Russell Keys is plagued by nightmares of his abduction by ...', runtime: 877, title: 'Taken' } ]
Perform an Update Based on Embedded Document Fields
This updateMany() operation matches an embedded
document named imdb, with a subfield named rating. It sets
{ highestRated: true } in each document where rating is greater than
or equal to 9.5.
db.movies.updateMany( { "imdb.rating" : { $gte: 9.5 } }, { $set: { "highestRated": true } } )
{ acknowledged: true, insertedId: null, matchedCount: 2, modifiedCount: 2, upsertedCount: 0 }
To set the higestRated field in only the first document where
imdb.rating is greater than 9.5, use
updateOne().