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