$lt and $gt are the two commands used to get the values greater than given value and less than given value, it is same as between in sql server.
$lte and $gte will used as 'less than or equal to' and 'greater than or equal to'
Better to use $lt and $gt in the given find statement to get the exact records, because Mongodb allows users to pass the different data types for the same field, giving both $lt and $gt will give the actual and expected output.
Let the initial data in the database be:
{ "pname" : "Apple", "Price" : 600, "Location" : "US" }
$lte and $gte will used as 'less than or equal to' and 'greater than or equal to'
Better to use $lt and $gt in the given find statement to get the exact records, because Mongodb allows users to pass the different data types for the same field, giving both $lt and $gt will give the actual and expected output.
Let the initial data in the database be:
{ "pname" : "Apple", "Price" : 600, "Location" : "US" }
{ "pname" : "Microsoft", "Price" : 400, "Location" : "UK" }
{ "pname" : "Motorolla", "Price" : 250, "Location" : "India" }
{ "pname" : "lenevo", "Price" : 230, "Location" : "Argentina" }
{ "pname" : "MI", "Price" : 290, "Location" : "Chile" }
{ "pname" : "samsung", "Price" : 320, "Location" : "Singapore" }
Using $lt and $gt for integer values
db.products.find({Price:{$gt:350}})
db.products.find({Price:{$lt:250}})
First statement will return the documents with Price greater than 350 and Second statement will return the documents of Price less than 250
Using $lte and $gte for string values
db.products.find({pname:{$gte:'h'}})
db.products.find({pname:{$lte:'D'}})
First statement will return the documents with pname ‘h’ and alphabetically greater than 'h' and Second statement will return the documents of pname with ‘D’ and alphabetically less than 'D'
Using $lt and $gt together
db.products.find({Price:{$gt:290,$lt:400}})
The above Query will return the documents of price greater than 290 and less than 400
{ "pname" : "samsung", "Price" : 320, "Location" : "Singapore" }
8 Comments
Thanks for publishing this blog, really awesome. Only experienced professional can do this.
ReplyDeleteDrupal Training in Chennai
Drupal Course in Chennai
Drupal Training
Photoshop Classes in Chennai
Photoshop Course in Chennai
Photoshop Training in Chennai
Drupal Training in OMR
Drupal Training in Porur
This comment has been removed by the author.
ReplyDeleteThis post is much helpful for us. This is really very massive value to all the readers and it will be the only reason for the post to get popular with great authority.
ReplyDeleteWeb Designing Course in chennai
Web Designing training in chennai
Big Data Training in Chennai
Blue Prism Training in Chennai
Advanced Java Training in Chennai
Software Testing Training in Chennai
German Language Course in Chennai
Web designing Training in Anna Nagar
ReplyDeleteI enjoy sawing your great post and this very impressed to me. I will share your post for my friend and keep continue your valid post...
Pega Training in Chennai
Pega Course in Chennai
Tableau Training in Chennai
Oracle Training in Chennai
Oracle DBA Training in Chennai
Social Media Marketing Courses in Chennai
Primavera Training in Chennai
Unix Training in Chennai
Such an amazing blog with new updates. I love to learn more about this topic. Waiting for more like this.
ReplyDeleteMicrosoft Dynamics crm Training in Chennai
Microsoft Dynamics Training in Chennai
Microsoft Dynamics crm Training institutes in Chennai
Salesforce Training in Chennai
AngularJS Training in Chennai
Tally course in Chennai
ccna course in Chennai
Microsoft Dynamics crm Training in Velachery
Microsoft Dynamics crm Training in T Nagar
Microsoft Dynamics crm Training in OMR
iso certification in noida
ReplyDeleteiso certification in delhi
ce certification in delhi
iso 14001 certification in delhi
iso 22000 certification cost
iso consultants in noida
Truly overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. Much obliged for sharing.business analytics training
ReplyDeleteGreat blog.you put Good stuff.All the topics were explained briefly.so quickly understand for me.I am waiting for your next fantastic blog.Thanks for sharing.Any coures related details learn...
ReplyDeleteCRM Solutions