EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials MongoDB Tutorial MongoDB greater than
Secondary Sidebar
MongoDB Tutorial
  • Advanced
    • MongoDB Array
    • PostgreSQL ARRAY_AGG()
    • Indexes in MongoDB
    • MongoDB create Index
    • MongoDB Collection
    • MongoDB List Collections
    • MongoDB Capped Collections
    • MongoDB Delete Collection
    • Mongodb show collections
    • MongoDB Auto Increment
    • MongoDB Triggers
    • MongoDB Projection
    • Replication in MongoDB
    • MongoDB Database
    • Mongo DB Create Database
    • MongoDB Compass
    • MongoDB Users
    • MongoDB Authentication
    • MongoDB GridFS
    • MongoDB Relationships
    • MongoDB MapReduce
    • MongoDB Geospatial
    • MongoDB Monitoring
    • Backup in MongoDB
    • MongoDB Sharding
    • MongoDB Java Drivers
    • MongoDB Import
    • Mongo Database Interview Questions
    • MongoDB Join Two Collections
    • MongoDB Group by Multiple Fields
    • MongoDB Pagination
    • MongoDB Replica Set
    • MongoDB Bulk Update
    • MongoDB greater than
    • MongoDB Encryption
    • MongoDB find in array
    • MongoDB like query
    • Mongodb shell
    • MongoDB port
    • MongoDB Query Operators
    • MongoDB Web Interface
    • MongoDB Query Array
    • MongoDB Transactions
    • MongoDB Not In
    • MongoDB not null
    • MongoDB npm
    • MongoDB Remove
  • Basics
    • What is MongoDB
    • How To Install MongoDB
    • MongoDB Tools
    • MongoDB GUI Tools
    • MongoDB Versions
    • MongoDB Commands
    • Advantages of MongoDB
    • MongoDB Features
    • Is MongoDB NoSQL
    • Is MongoDB Open Source
    • Build Web Applications using MongoDB
    • MongoDB Data Types
    • MongoDB Administration
    • Data Modeling in MongoDB
    • MongoDB vs Elasticsearch
    • MariaDB vs MongoDB
    • Firebase vs MongoDB
  • Commands
    • Mongodb updateMany
    • MongoDB Aggregation
    • Mongodb unwind
    • Mongodb where
    • MongoDB BSON
    • MongoDB Filter
    • Mongodb Match
    • MongoDB sort by date
    • MongoDB Limit()
    • MongoDB Atlas Login
    • MongoDB Relational Database
    • MongoDB count
    • MongoDB Aggregate
    • MongoDB Distinct
    • MongoDB Unique
    • MongoDB find
    • MongoDB findOne()
    • MongoDB insert
    • MongoDB Delete
    • MongoDB Update
    • Lookup in MongoDB
    • order by in MongoDB
    • MongoDB $regex
    • MongoDB $elemMatch
    • MongoDB ObjectId()
    • MongoDB Skip()
    • MongoDB findAndModify
    • Mongodb findOneAndUpdate
    • MongoDB Date Query
    • MongoDB Timestamp
    • MongoDB sort()
    • MongoDB group by
    • MongoDB Join

Related Courses

MongoDB Certification Course

Oracle Certification Course

All in One Data Science Course

SQL Training Course

Oracle DBA Course

MS SQL Certification Course

MongoDB greater than

MongoDB greater than

Definition of Mongodb greater than

MongoDB provides a different kind of comparison operator to the user, the greater than is one of the comparison operators that are provided by the MongoDB. Normally MongoDB is greater than the comparison operator, it is used to compare the two different values such as specified value and filed value. Basically greater than operator is used to fetching the required document where the value of a field from the collection is greater than the specified value. Greater than operator we can use different methods such as like, find and update as per our requirement. The MongoDB greater than comparison operator we can denote by using the $gt symbol.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,112 ratings)

Syntax:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

{specified field name:{$gt: specified value}}

Explanation

In the above syntax, we use the comparison operator of MongoDb that is greater than ($gt) with two different parameters as follows.

  • specified field name: it is used to field name from the collection and this field is dependent on the user.
  • $gt: it is the symbol of greater than comparison operator
  • specified value: It is used to define the value for the comparison

How greater than works in MongoDB?

Now let’s see how the greater than comparison operator works in MongoDB as follows.
First, try to understand what the operator is. MongoDB provides different kinds of operators such as comparison, logical, element array and bitwise, etc. But we commonly used comparison operators among the different operators. Again we have different types of comparison operators such as eq, gt, lt, and gte, etc, and this operator we can use as per our requirement.

Normally greater than operator is used to compare the specified value with all documents from the collection and we found any match and if match value is greater than the specified value then it displays all documents from the collection.
The working of greater than operator is simple; we just need to mention the specified field name with the specified value that we want. The specified field name and specified value depend on the user. At the time of execution, it compares all specified values with all documents from the collection and if the value of the document is greater than the specified value then it displays specified records.

Example

Now let’s see the different examples of greater than operator as follows.

First, we need to create the new collection as follows.

First, we need to use a database then create a collection as follows.

First, we created a sample database by using the following statement as follows.

use sample

Explanation

In the above statement, we use the command to create the new database, here we successfully created a sample database and we use it. The final output of the above statement we illustrated by using the following screenshot as follows.

MongoDB greater than 1

After successful creation of the database, we need to create the collection by using the following statement as follows.

db.createCollection("student")

Explanation

In the above statement, we use createCollection command to create the new collection; here we created a new collection name as a student as shown. The final output of the above statement we illustrated by using the following screenshot as follows.

MongoDB greater than 2

Now we have a collection, so now we need to insert the same document into the newly created collection that is a student by using the following statement as follows.

db.student.insert({ name: "Johan", dept: "IT", marks: 75, dbsm:56})
db.student.insert({ name: "Sameer", dept: "comp", marks: 12, dbsm:45})
db.student.insert({ name: "pooja", dept: "comp", marks: 45, dbsm:65})
db.student.insert({ name: "Rohit", dept: "mech", marks: 71, dbsm:87})
db.student.insert({ name: "Sachin", dept: "IT",marks: 98, dbsm:74})

Explanation

By using the above statement we successfully inserted five documents into the student collection, in which we inserted the name of the student, department name of the student, marks of a student, and marks of DBMS subject as shown. The final output of the above statements we illustrated by using the following screenshot as follows.

output

Now we can perform MongoDB greater than ($gt) comparison operator as follows.

db.student.find({marks:{$gt:20}})

Explanation

In the above example, we need to find out those student marks greater than 20 at that time we can use the above statement. Here we first specify the collection name that is a student after that we use the find function with marks filed and user-specified value as shown. The final output of the above statement we illustrated by using the following screenshot as follows.

MongoDB greater than 3

Now let’s see more examples of $gt as follows.

Suppose we need that student marks is greater than 80 at that time we can use the following statement as follows.

db.student.find({marks:{$gt:80}})

Explanation

In the above example, we use a comparison operator of MongoDB that is greater than, in this example, we need to find those students whose marks are greater than 80 as shown. The final output of the above statement we illustrated by using the following screenshot as follows

MongoDB greater than 5

Now let’s see how we can use the update method with the $gt comparison operator as follows.

db.student.update( { "marks": { $gt: 70 } }, { $set: { dbms: 95 } } )

Explanation

In the above example, we try to implement the update method with the $gt comparison operator, in this example, we set the DBMS marks of students by using the $gt operator. Here we set 95 DBMS marks; those student marks are greater than 70 as shown in the above statement. The final output of the above statement we illustrated by using the following screenshot as follows.

MongoDB greater than 4

We can also set the multi: true option in the update method as per our requirement as follows.

db.student.update( { "marks": { $gt: 70 } }, { $set: { dbms: 95 } }, {multi: true} )

Explanation

In the above example, we use the multi true option with the update method, here we set the DBMS marks the same as the previous example, the only difference is that when the condition is true then the multi-option is true. This condition is dependent on the user requirement. The final output of the above statement we illustrated by using the following screenshot as follows.

ss

Conclusion

We hope from this article you learn more about MongoDB greater than. From the above article, we have learned the basic syntax of the greater than and we also see different examples of the greater than. From this article, we learned how and when we use MongoDB greater than.

Recommended Articles

This is a guide to MongoDB greater than. Here we discuss the definition, How greater than works in MongoDB? along with examples respectively. You may also have a look at the following articles to learn more –

  1. MongoDB Timestamp
  2. MongoDB Skip()
  3. Backup in MongoDB
  4. MongoDB GridFS
Popular Course in this category
MongoDB Training Program (4 Courses, 2 Projects)
  4 Online Courses |  2 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle Training (14 Courses, 8+ Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
SQL Training Program (7 Courses, 8+ Projects)4.7
Oracle DBA Database Management System Training (2 Courses)4.7
MS SQL Training (16 Courses, 11+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more