MongoDB projection
The MongoDB projection meaning is to select only the data you want, not the entire document. If a document has 5 fields, you only need to display 3, and only select 3 fields from it.
MongoDB's Find () method, which explains the second optional parameter in MongoDB that the query document receives is the list of fields to retrieve. In MongoDB, when the Find () method is executed, it displays all the fields of a document. To limit this, you need to set the field list value to 1 or 0. 1 is used to display the field, while 0 is used to hide the field.
Grammar
The basic syntax for the Find () method is 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 Yiibai Overview "}
The following example displays the title of the document when querying the document.
>db.. Find ({},{ "title" :1,< Span class= "PLN" >_id:0}) { "title" : "MongoDB Overview" }{ "title" : "NoSQL Overview" }{ "title" : "Yiibai Yiibai Overview" } >
Note that the _id field is always displayed when you execute the Find () method, and if you do not want to display this field, you need to set it to 0
MongoDB Quick Start (ix)