MongoDB Tutorial Lesson 14th MongoDB Projection

Source: Internet
Author: User
Tags mongodb projection mongodb query mongodb tutorial

MongoDB projection means to select only the necessary data instead of selecting the entire data for a file. If a document has 5 fields, you need to display only 3, and then select only 3 fields.

Find () method

MongoDB's Find () method, which is interpreted in the MongoDB query document, accepts the second optional parameter that is the list of fields to retrieve. In MongoDB, when the Find () method is executed, it displays all fields of a document. To limit this, you need to set the field List value 1 or 0. 1 is used to display the field and 0 is used to hide the field.

Grammar:

The Find () method has a projection basic syntax as follows

>db.  Collection_name.  Find({},{KEY:1})         
Example

Consider the collection Myycol with the following data

{ "_ID" : ObjectId(5983548781331adf45ec5), "Title":"MongoDB Overview"}{  "_id" : objectid ( 5983548781331adf45ec6  "title" : "NoSQL Overview" }{ "_id"  : objectid5983548781331adf45ec7  " Title ":" Yiibai Overview "}      

The following example will show the title of the file and a few questions about the file.

>db.. Find ({},{ "title" :1,< Span class= "PLN" >_id:0}) { "title" : "MongoDB Overview" }{ "title" : "NoSQL Overview" }{ "title" : "Yiibai Overview" }                  

MongoDB Tutorial Lesson 14th MongoDB Projection

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.