MongoDB Greater than Operation - MongoDB Tutorial



MongoDB Greater Than Operation

  • In mongoDB “$gt” selects the documents where the value of the field is greater than (i.e. >) the specified value.
  • And the comparison process will be done by only the fields of the documents where as BSON type matches the query value’s type.

Syntax :

{field: {$gt: value} 

Sample Query :

> db.wikitechy4.insert({
... "websitename": "www.wikitechy.com",
... "details":"row to check less than",
... "articlepoints":10,
... "author":"jln"
... })

WriteResult({ "nInserted" : 1 })

> db.wikitechy4.insert({
... "websitename": "www.wikitechy.com",
... "details":"row to check less than",
... "articlepoints":50,
... "author":"arun"
... })

WriteResult({ "nInserted" : 1 })

> db.wikitechy4.find(
               {"articlepoints":{$gt:20}}
            ).pretty()

{
        "_id" : ObjectId("5731ff77daa4a0bc932a3000"),
        "websitename" : "www.wikitechy.com",
        "details" : "row to check less than",
        "articlepoints" : 50,
        "author" : "jln"
}
>

MongoDb


Output

MongoDb
  1. Here in this statement, the data’s “websitename”:www.wikitechy.com” , ”details”:”row to check less than”,”articlepoints”:”10” and the “author “ : “jln” are being inserted into the collection ”wikitechy4”.
  2. Here this statement, we add another row of data’s “websitename”:www.wikitechy.com” ,”details”:”row to check less than”,”articlepoints”:”50” and the “author “ : “arun” are being inserted into the collection ”wikitechy4”.
  3. In this statement we perform a greater than operation where the “articlepoint:” value must be greater than “20” , thereby it displays the data’s “websitename”:www.wikitechy.com” ,”details”:”row to check less than”,”articlepoints”:”50” and the “author “ : “arun”.


Related Searches to MongoDB Greater than Operation - MongoDB Tutorial