Below some example of Where condition in MongoDB.
pretty: using for just formatting of data view.
Equal To:
          > db.student.find({“name”: “Mohan” }).pretty()
Less Than:
          > db.student.find({“marks”:{$lt:50}}).pretty()
Less Than Equals:
          > db.student.find({“marks”:{$lte:50}}).pretty()
Greater Than:
          > db.student.find({“marks”:{$gt:50}}).pretty()
Greater Than Equals:
          > db.student.find({“marks”:{$gte:50}}).pretty()
Not Equals:
          > db.student.find({“marks”:{$ne:50}}).pretty()
AND Condition in MongoDB
Multiple keys by separating them by ‘,’ then MongoDB treat as AND condition.
          > db.student.find({$and:[{“rollno”:105},{“name”: “Dan”}]})
OR Condition in MongoDB
          > db.student.find({$or:[{“rollno”:104},{“rollno”: 105}]})

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.