$gt means greater than. Use it to filter documents where a field exceeds a value, or in aggregation to return true / false from a comparison. Equality does not match—use $gte for that.
Pick filter mode (keep documents) or expression mode (boolean field).
For filtering: use find() or $match with { field: { $gt: value } }.
For a boolean: use $addFields / $project with { $gt: [ expr1, expr2 ] }.
To compare two fields in a filter, wrap with $expr.
Use $gte when the boundary value should also match.
Piece
Required?
Role
Query form
—
{ field: { $gt: value } } filters docs
Expression form
—
{ $gt: [ a, b ] } → boolean
Operands
Yes
Same BSON type when possible
Pseudocode
Pseudocode
// Filter mode
for each document:
if field > threshold:
keep document
else:
drop document
// Expression mode
for each document:
result = (expr1 > expr2) // true or false
emit { ..., field: result }
Reference
Cheat Sheet
Keep these facts handy while writing greater-than checks.
Topic
Detail
Meaning
Greater than (excludes equals)
Query syntax
{ field: { $gt: value } }
Agg syntax
{ $gt: [ <a>, <b> ] }
vs $gte
$gte includes equality
Two fields in find
Use $expr + $gt
Types
Numbers, dates, strings (BSON order)
Sample check
score: { $gt: 80 } keeps 85, drops 80
Try it
Live Preview
Watch $gt test whether a score is greater than 80.
Same stored documents. Still using Asha and Ben from Example 1.
Compare as an expression.{ $gt: ["$score", 80] } returns a boolean per document.
Nothing is dropped. Both rows stay; only the new passed flag differs.
Edge Cases & Pitfalls
Check these before using $gt in production queries.
equals
Equals do not match
{ score: { $gt: 80 } } excludes 80. Use $gte when the boundary should pass.
types
Type mismatches surprise
Comparing a number to a string uses BSON type order, not numeric math. Keep types consistent.
fields
Two fields need $expr in find
To filter with spent > budget, use $expr: { $expr: { $gt: ["$spent", "$budget"] } }.
index
Range filters love indexes
An index on the compared field helps $gt / $gte range scans stay fast on large collections.
Analysis
Performance Notes
Approach
Cost
Best for
Indexed $gt filter
Range scan
Large collections with a field index
Unindexed $gt
Collection scan
Small data or rare queries
Agg boolean $gt
Per-document compare
Flags without dropping rows
Put selective $gt filters early in $match so later stages see fewer documents.
Remember
Key Takeaways
Role: strict greater-than comparison.
Filter:{ field: { $gt: value } }.
Expression:{ $gt: [ a, b ] } → boolean.
Equals: use $gte when the boundary should match.
One line:$gt answers “is this value strictly greater than that?”—as a filter or as a boolean.
Frequently Asked Questions
$gt means greater than. In a query filter it keeps documents where a field is greater than a value. In aggregation expressions it compares two expressions and returns true or false.
Query form: { field: { $gt: value } }. Aggregation form: { $gt: [ <expression1>, <expression2> ] }. There is no shorthand like { field: value } for greater-than.
$gt is strict greater than (excludes equality). $gte is greater than or equal (includes equality).
Yes in aggregation: { $gt: [ "$spent", "$budget" ] }. In a find filter, compare two fields with $expr and $gt.
Yes. Numbers compare numerically, dates chronologically, and strings lexicographically. Keep operand types consistent for predictable results.
In find()/ $match filters to select documents, and in expression stages like $project and $addFields to create boolean fields.