3.4.2 Data Query
In the MongoDB database, the support for database queries is in place, with relational operations, logical operations, array operations, and regular operations.
For the query operation core syntax for data:
Db. Collection name. Find ({query criteria} {set displayed fields})
example : No query criteria
Db.info.find ()
Example : Query criteria for querying data with URL "www.mldn.cn"
Db.info.find ({"url": "Www.mldn.cn"})
A data query is an equality relationship that is set in the form of JSON. It is impossible to leave JSON data throughout its development.
The display field for the setting is strictly referred to as the projection operation of the data. The field you do not need to display is set to "0" and the field you want to display is set to "1".
The projection operation is a small portion of the entire database that is displayed. For example: The database has department number, department name, department position, but only want to show department number, department name display, department position is not displayed, this is the projection operation.
Example : Don't want to show ID
In most cases, the projection operation is of little significance.
Queries for data can also be beautifully displayed using the "pretty ()" function.
Example : Beautiful display
Db.info.find ({"url": "www.mldn.cn"}, {"_id": 0, "url": 1}). Pretty ()
When the data column is not displayed, many times can be seen.
Example : Single Query
Db.info. FindOne ({"url": "www.mldn.cn"}, {"_id": 0, "url": 1})
MongoDB (Lesson 5 data query)