MongoDB versus RDBMS Where statement comparison
Operation |
format |
Example |
similar statements in an RDBMS |
Equals |
{<key>:<value> } |
db.col.find({"by":"XXXX"}).pretty() |
where by = ‘XXXX‘ |
Less than |
{<key>:{$lt:<value>}} |
db.col.find({"likes":{$lt:50}}).pretty() |
where likes < 50 |
Less than or equal to |
{<key>:{$lte:<value>}} |
db.col.find({"likes":{$lte:50}}).pretty() |
where likes <= 50 |
Greater than |
{<key>:{$gt:<value>}} |
db.col.find({"likes":{$gt:50}}).pretty() |
where likes > 50 |
Greater than or equal to |
{<key>:{$gte:<value>}} |
db.col.find({"likes":{$gte:50}}).pretty() |
where likes >= 50 |
Not equal to |
{<key>:{$ne:<value>}} |
db.col.find({"likes":{$ne:50}}).pretty() |
where likes != 50 |
MongoDB and condition
The MongoDB find () method can pass in multiple keys (key), each separated by commas, which is the and condition of the regular SQL.
The syntax format is as follows:
DB col find ({ key1 : value1 Key2 : value2 }) . pretty ()
MongoDB OR Condition
DB.Col.Find( {$or: [ {Key1:value1}, { key2 : value2 } ] } ). pretty ()
Example:
db.getcollection (' products '). Find ({$or: [{"_id": "Xclient_ Jiyinshuoxilie "}, {" _id ":" Changdaokang_meiyinjiyin "}]}). Pretty ()
Combined with and OR
DB. Col. Find({"likes":{$gt:-}, $or:[{"by":" Xxxxxxxxxx "},{" title ":" MongoDB XXXXXX "}]}). Pretty()
MongoDB Query Document