Definition
$gt$gtselects documents where the value of the field is greater than (>) 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 $gt 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 $gt operator has this form:
{ field: { $gt: 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 1000 minutes:
db.movies.find( { runtime: { $gt: 1000 } }, { _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 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' } ]
Perform an Update Based on Embedded Document Fields
This updateMany() operation matches an embedded
document named imdb, with a subfield named rating. The operation
sets { highestRated: true } in documents where rating is greater
than 9.5.
db.movies.updateMany( { "imdb.rating" : { $gt: 9.5 } }, { $set: { "highestRated": true } } )
{ acknowledged: true, insertedId: null, matchedCount: 1, modifiedCount: 1, upsertedCount: 0 }