MongoDB Chinese Document: http://docs.mongoing.com/manual-zh/contents.html
Here, for example, with the collection name test, the database inserts some test data through a for loop, with the keys: name,age,date
db.test.find () querying all the data
Db.test.findOne () queries a single piece of data, returning the first inserted data, which can no longer be followed by other query conditions, such as: Db.test.findOne (). Sort ({age:1}), reported: Has no Method ' Sort '
db.test.find ({age:18}) query for data aged 18
db.test.find ({age:18}) [0] Queries age 18, the index in the resulting document is 0, andMongoDB's query returns the document documents (except the aggregate function ...), so you can take
db.test.find (). Skip (1). Srot ({age:1}) is ordered in the positive order of age (1 is positive, 1 is reverse ), and the result set skips the first data (Skip ( 1)) The first 10 data
db.test.find ({},{name:1,age:1,date:-1}) queries all data, and the columns in the result set contain only name, age, and not: date. The first bracket is the condition of the query, and the null representation queries all non-_id fields: 1 is displayed, 1 is hidden; _id field: Not specified as display, 0 is hidden
Db.test.find ({age:{$gt:)) queries all information older than 18,$GT is greater than,$lt is less than
Db.test.find ({age:{$in: [17,18,19]}}) queries age=17, 18, 19 data, with SQL in
Insert two data for continuation, multiple sex keys:
Db.test.insert ({name: "Testss", age:20,sex:1})
Db.test.insert ({name: "Tdfdaf", age:20,sex:0})
db.test.find ({age:{$lt: 21},sex:1}) query for data that is less than 21 and has a gender of 1, which is SQL's and query
Db.test.find ({$or: [{age:20},{sex:1}]}) query for data with age 20, or 1 for gender, that is, SQL or query
Db.test.find ({age:{$lt: A, $or: [{age:20},{sex:1}]}) used with and and or, multi-analysis analyst Three statement, writing format
The query in MongoDB