A brief analysis of MONGODB query statement

Source: Internet
Author: User
Tags mongodb query

Find () statementstart the MongoDB service because MongoDB does not start with the system, and it may take a short period of time for the following commands to start to complete.
sudo service MongoDB start

Enter the MongoDB command line operator interface and tap on the command lineExitcan exit
Mongo

Find () Usage: db. Collection_name.find ()
> Use post #创建post数据库 and insert document into it > Db.post.insert ([{   title: ' MongoDB Overview ',    Description: ' MongoDB is no SQL database ', by   : ' Shiyanlou ',   URL: ' http://www.shiyanlou.com ',   Tags: [' mongodb ', ' database ', ' NoSQL '],   likes:100},{   title: ' NoSQL database ',    description: "NoSQL database doesn ' t has tables", by   : ' Shiyanlou ',   URL: ' http://www.shiyanlou.com ',   Tags: [' mongodb ', ' database ', ' NoSQL '],   likes:20,    Comments: [          {         User: ' User1 ',         message: ' My first comment ',         datecreated:new Date (2013,11,10,2,35),         like:0       }   ]}])

Querying data, returning all data records by default without any parameters:
Db.post.find ()
Pretty () statementpretty () can make the results of the query output more aesthetically pleasing.
Db.post.find (). Pretty ()

And in MongoDBwhen multiple key-value pairs are passed in Find (), MongoDB handles them as an and query. Usage: Db.mycol.find ({key1:value1, key2:value2}). Pretty ()
Db.post.find ({"By": "Shiyanlou", "title": "MongoDB Overview"}). Pretty ()

The OR in MongoDBin MongoDB, OR query statements with $or as keywords, use the following:
> Db.post.find (   {      $or: [         {key1:value1}, {key2:value2}      ]   }). Pretty ()

Use both and and OR
> db.post.find ({    "likes": {$gt: ten},    $or: [        {"by": "Shiyanlou"},        {"title": "MongoDB Overview"}    ]}). Pretty () #<span style= "Color:rgb (51, 51, 51); font-family: ' Microsoft Yahei '; font-size:16px; line-height:25.59375px; " >{\ $GT: 10} represents greater than 10, in addition, \ $lt represents less than, \ $lte represents less than equals, \ $gte represents greater than or equal, \ $ne represents not equal. </span>



A brief analysis of MONGODB query statement

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.