MongoDB (Lesson 5 data query)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.