MongoDB Less than Operation - MongoDB Tutorial



MongoDB Less Than Operation

  • In mongoDB “$lt” selects the documents where the value of the field is less 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: {$lt: 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":{$lt:20}}
            ).pretty()

{
        "_id" : ObjectId("5731ff77daa4a0bc932a3000"),
        "websitename" : "www.wikitechy.com",
        "details" : "row to check less than",
        "articlepoints" : 10,
        "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 lesser than operation where the “articlepoint:” value must be lesser than “20” , thereby it displays the data’s “websitename”:www.wikitechy.com” , ”details”:”row to check less than”,”articlepoints”:”10” and the “author “ : “jln”


Related Searches to MongoDB Less than Operation - MongoDB Tutorial