MongoDB $gt Operator (original) (raw)

Last Updated : 5 May, 2026

The $gt operator in MongoDB matches documents where a field’s value is greater than a specified value. It is commonly used with find(), update(), and aggregation pipelines for filtering, analysis, and range-based queries.

Syntax

{field: {$gt: value}}

Features of $gt Operator

The $gt operator is flexible and efficient for filtering documents greater than a given value across different query methods.

Examples of MongoDB $gt Operator

Consider the following sample data. We will use a database named GeeksforGeeks and a collection called employee, which contains the following documents:

Screenshot-2026-02-09-111501

Example 1: Find Employees with a Salary Greater Than 35,000

Retrieving those documents where the value of the salary field is greater than 35000.

**Query:

db.employee.find({salary: {$gt: 35000}})

**Output:

Screenshot-2026-02-09-110622

Example 2: Find Employees with Age Greater Than 23

Retrieving only those documents where the age of the employee is greater than 23.

**Query:

db.employee.find({"personalDetails.age": {$gt:23}})

**Output:

Screenshot-2026-02-09-110752

The query uses dot notation to access the nested age field inside the personalDetails document and applies the $gt operator.

Example 3: Using $gt operator with arrays

Retrieving only those documents where the points array is greater than the specified array.

**Query:

db.employee.find({points: {$gt: [4,5]}})

**Output:

Screenshot-2026-02-09-110933

The query compares the points array with [4, 5] using lexicographical ordering, where elements are compared sequentially from left to right.

Use Cases of $gt Operator

The $gt operator is used to filter documents where a field value is greater than a specified threshold.