1. Query the document in the collection, you can use the command DB. Collection name. Find ({condition}), or use DB. Collection name. FindOne () query the first document
2. Query the document in the collection to return some specific key values
3. Query the document in the collection, using the conditional expression (<, <=,;, >=,!=)
Greater than: field > Value
Db.collection.find ({field:{$gt: value}});
Less than: Field < value
Db.collection.find ({field:{$lt: value}});
Greater than or equal to: field >= value
Db.collection.find ({field:{$gte: value}});
Less than equals: field <= value
Db.collection.find ({field:{$lte: value}});
Not equal to: field! = value
Db.collection.find ({field:{$ne: value}});
4. Querying the collection for documents, statistics (count), sorting (sort), paging (skip, limit)
Db.customer.count ();
Db.customer.find (). Count ();
Db.customer.find ({age:{$lt: 5}}). Count ();
Db.customer.find (). Sort ({age:1});
Db.customer.find (). Skip (2). Limit (3);
Db.customer.find (). Sort ({age:-1}). Skip (2). Limit (3);
Db.customer.find (). Sort ({age:-1}). Skip (2). Limit (3). Count ();
Db.customer.find (). Sort ({age:-1}). Skip (2). Limit (3). Count (0);
Db.customer.find (). Sort ({age:-1}). Skip (2). Limit (3). Count (1);
5. Querying a document in a collection, $all is primarily used to query the containing relationship in an array, and the query condition does not return as long as there is one that does not contain
6. Query the document in the collection, $in, similar to in in the relational database
7. Query the document in the collection, $nin, as opposed to $in
8. Query the document in the collection, $or, equivalent to or in a relational database, or a relationship, such as querying a document with name User2 or age 3,
The command is: Db.customer.find ({$or: [{name: "User2"},{age:3}]})
9. Query the document in the collection, $nor, to filter out some of the data according to the criteria, for example, the query name is not a user2,age 3 document,
The command is: Db.customer.find ({$nor: [{name: "User2"},{age:3}]})
10. Query the document in the collection, $exists, to query a document that has a key in the collection, or a document that does not have a key, such as querying all documents that have the name key in the customer collection, you can use Db.customer.find ({name:{$exists : 1}}),
$exists: 1 means true, meaning existence
$exists: 0 means false, meaning that there is no
11. Query the collection of documents, similar to relational database, MongoDB also has the concept of cursors
MongoDB common Operations--collection 2