One, MongoDB data query
(1) MongoDB uses the Find function to query data, with the same functionality as the Select function in SQL, which can provide many functions similar to the relational database, including mapping, sorting, and so on.
Db. Collection name. Find (Query,fields,limit,skip)
1.query is equivalent to the WHERE statement in SQL
2.fields is used for field mapping, 1 indicates that display 0 is not displayed, syntax format: {field:0} or {field:1} use either full 0 or full 1, mixed use except "_id": 0 Mixed usage is wrong.
3.limit limits the number of documents in the query result set.
4.skip skips the result of a certain amount of data, setting the offset of the first returned document.
(2) MongoDB and matters needing attention
1.MongoDB does not support the connection query between multiple collections, the Find function can only be used for a single set of queries.
If the 2.find parameter is null or the query condition is empty, the document in the collection is returned.
3. In addition to using limit and skip as arguments to the Find function, you can use the limit and skip functions separately to decorate the query results.
For example: Db.student.find ({age:{$lt:}}). Limit (5). Skip (10)
4. The returned query result set is unordered by default, and if you need to sort the results, you can use the sort function. 1 means ascending-1 is descending.
Example: Db.student.find (). Sort ({name:1,age:-1})
5.db.collection.findone () returns only the first data.
6. When the number of collection documents for a query is large, an index can be created to speed up the query speed of the data.
7. In addition to using the Find function to implement basic queries, MongoDB also provides an aggregation framework for complex queries.
Second, the query operator introduction and use
(1) Compare query operators
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/99/CB/wKiom1lMkXngJbz5AABpnVBwqjA326.jpg "title=" 04. JPG "alt=" wkiom1lmkxngjbz5aabpnvbwqja326.jpg "/>
(2) Logical query operator
A logical query operator that can connect multiple query conditions for logical and, or, non-, and inverse operations.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/99/CB/wKioL1lMk7CjkZyIAABtjk-hEGg651.jpg "title=" 05. JPG "alt=" wkiol1lmk7cjkzyiaabtjk-hegg651.jpg "/>
(3) Element operator
The element query operator, which is used to query the properties of a field in a document, including whether the field exists and the field's data type.
650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M01/99/CB/wKiom1lMlC3zHWhqAABKOXhsV1k629.jpg "title=" 06. JPG "alt=" wkiom1lmlc3zhwhqaabkoxhsv1k629.jpg "/>
MongoDB Notes (iii)