Below some example of Where condition in MongoDB.
pretty: using for just formatting of data view.
Equal To:
{<key>:<value>}
> db.student.find({“name”: “Mohan” }).pretty()
Less Than:
{<key>:{$lt:<value>}}
> db.student.find({“marks”:{$lt:50}}).pretty()
Less Than Equals:
{<key>:{$lte:<value>}}
> db.student.find({“marks”:{$lte:50}}).pretty()
Greater Than:
{<key>:{$gt:<value>}}
> db.student.find({“marks”:{$gt:50}}).pretty()
Greater Than Equals:
{<key>:{$gte:<value>}}
> db.student.find({“marks”:{$gte:50}}).pretty()
Not Equals:
{<key>:{$ne:<value>}}
> 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}]})