MongoDB uses find to query, returning a subset of the documents in a collection;
Returns all documents in the Document collection blog:
> Db.post.find () {"_id": ObjectId ("54a530c3ff0df3732bac1681"), "id": 2, "name": "Joe", "age": +, "sex": 1, "SC Hool ":" Marry "} {" _id ": ObjectId (" 54a530c3ff0df3732bac1680 ")," id ": 1," name ":" Joe "," age ": +," comments ": [ "Test2", "Test9", "Test5"], "sex": 1, "school": "Marry"} >
Returns the specified document:
> Db.post.find ({"id": 1}) {"_id": ObjectId ("54a530c3ff0df3732bac1680"), "id": 1, "name": "Joe", "Age": "comme NTS ": [" Test2 "," Test9 "," Test5 "]," sex ": 1," school ":" Marry "} >
Returns the specified key value:
> db.post.find ({},{"id": 1, "Age": 1}) {' _id ': ObjectId ("54a530c3ff0df3732bac1681"), "id": 2, "age": $ {"_id" : ObjectId ("54a530c3ff0df3732bac1680"), "id": 1, "Age": >
The default is always to return the "_id" key, and the following method can not return "_id" key:
> db.post.find ({},{"id": 1, "Age": 1, "_id": 0}) {"id": 2, "age": +} {"id": 1, "Age": +} >
You can combine multiple criteria, such as querying a document with the name "Joe" and an ID of 1:
> db.post.find ({"Name": "Joe"}) { "_id" : objectid (" 54a530c3ff0df3732bac1681 "), " id " : 2, " name " : " Joe ", " Age " : 30, "Sex" : 1, "school" : "Marry" } { "_id"  : objectid ("54a530c3ff0df3732bac1680"), "id" : 1, "name" : "Joe", "age" : 30, "Comments" : [ "Test2", "Test9", "test5" ], "Sex" : 1, "School" : "Marry" } > db.post.find ({"Name" : "Joe", "id": 1}) { "_id" : objectid ("54a530c3ff0df3732bac1680"), "id " : 1, " name " : " Joe ", " age " : 30, " comments " : [ "Test2", "Test9", "test5" ], "Sex" : 1, "school" : "Marry"  } >
This article is from the "Margin with Wish" blog, please be sure to keep this source http://281816327.blog.51cto.com/907015/1599149
"MongoDB Learning Note 14" MongoDB Query: Find basics