MongoDB $gt Operator (greater than)What is the $gte operator in MongoDB?MongoDB provides a variety of comparison query operators. The $gte (greater than equal to) operator is one of those operators. The $gte operator is used to select documents where the value of the field is greater than or equal to (i.e. >=) the given value. You can use this operator in the update, find, like method as per your requirements. Syntax of the $gte operator:Examples:In the following examples, we are working with: >db.employee.find() { "_id" : 1, "name" : "John", "father_name" : "Thomas", "department" : "Contain Writting", "experience" : 2, "mobile_no" : 9856321478, "gender" : "Male", "salary" : 22000, "age" : 26 } { "_id" : 2, "name" : "William", "father_name" : "Rebort", "department" : "Softwre Tester", "experience" : 1, "mobile_no" : 7896541478, "gender" : "Male", "salary" : 20000, "age" : 21 } { "_id" : 3, "name" : "Ava", "father_name" : "William", "department" : "Marketing manager", "experience" : 5, "mobile_no" : 8789654178, "gender" : "Female", "salary" : 36500, "age" : 25 } { "_id" : 4, "name" : "Olivia", "father_name" : "Noah", "department" : null, "experience" : 4, "mobile_no" : 9045641478, "gender" : "Female", "salary" : 30000, "age" : 27 } { "_id" : 5, "name" : "Elijah", "father_name" : "John", "department" : "HR", "experience" : 0, "mobile_no" : 6589741230, "gender" : "Male", "salary" : 15000, "age" : 20 } { "_id" : 6, "name" : "John", "father_name" : "Liam", "department" : "Softwre Tester", "experience" : 10, "mobile_no" : 9014536987, "gender" : "Male", "salary" : 55000, "age" : 30 } Example 1: Using $gte operator In this example, we are looking for documents whose salary scale is equal to or greater than 20000 Output: { "_id" : 1, "name" : "John", "father_name" : "Thomas", "department" : "Contain Writting", "experience" : 2, "mobile_no" : 9856321478, "gender" : "Male", "salary" : 22000, "age" : 26 } { "_id" : 2, "name" : "William", "father_name" : "Rebort", "department" : "Softwre Tester", "experience" : 1, "mobile_no" : 7896541478, "gender" : "Male", "salary" : 20000, "age" : 21 } { "_id" : 3, "name" : "Ava", "father_name" : "William", "department" : "Marketing manager", "experience" : 5, "mobile_no" : 8789654178, "gender" : "Female", "salary" : 36500, "age" : 25 } { "_id" : 4, "name" : "Olivia", "father_name" : "Noah", "department" : null, "experience" : 4, "mobile_no" : 9045641478, "gender" : "Female", "salary" : 30000, "age" : 27 } { "_id" : 6, "name" : "John", "father_name" : "Liam", "department" : "Softwre Tester", "experience" : 10, "mobile_no" : 9014536987, "gender" : "Male", "salary" : 55000, "age" : 30 } Example 2: Another field In this example, we're looking for documents whose age is greater than or equal to 26. Output: { "_id" : 1, "name" : "John", "father_name" : "Thomas", "department" : "Contain Writting", "experience" : 2, "mobile_no" : 9856321478, "gender" : "Male", "salary" : 22000, "age" : 26 } { "_id" : 4, "name" : "Olivia", "father_name" : "Noah", "department" : null, "experience" : 4, "mobile_no" : 9045641478, "gender" : "Female", "salary" : 30000, "age" : 27 } { "_id" : 6, "name" : "John", "father_name" : "Liam", "department" : "Softwre Tester", "experience" : 10, "mobile_no" : 9014536987, "gender" : "Male", "salary" : 55000, "age" : 30 } Example 3: Update the value using the $gte operator In this example, we're updating the salary field for employees who have greater than or equal to 3 years of work experience. Output: { "_id" : 3, "name" : "Ava", "father_name" : "William", "department" : "Marketing manager", "experience" : 5, "mobile_no" : 8789654178, "gender" : "Female", "salary" : 50000, "age" : 25 } { "_id" : 4, "name" : "Olivia", "father_name" : "Noah", "department" : null, "experience" : 4, "mobile_no" : 9045641478, "gender" : "Female", "salary" : 50000, "age" : 27 } { "_id" : 6, "name" : "John", "father_name" : "Liam", "department" : "Softwre Tester", "experience" : 10, "mobile_no" : 9014536987, "gender" : "Male", "salary" : 50000, "age" : 30 } Next TopicMongoDB $lt Operator |