MongoDB Query Document

Source: Internet
Author: User
Tags mongodb find mongodb query

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.