In MongoDB, projection approach selecting simplest the necessary statistics rather than choosing entire of the data of a record. If a file has five fields and you want to show only 3, then select only 3 fields from them.
The discover() Method
MongoDB's find() approach, explained in MongoDB Query Document accepts second optionally available parameter this is listing of fields that you need to retrieve. In MongoDB, while you execute locate() method, then it shows all fields of a record. To restrict this, you need to set a listing of fields with cost 1 or zero. 1 is used to reveal the sector whilst 0 is used to hide the fields.
Syntax
The primary syntax of find() technique with projection is as follows −
>db.COLLECTION_NAME.find({},{KEY:1})
Example
Consider the gathering mycol has the subsequent records −
{_id : ObjectId("507f191e810c19729de860e1"), title: "MongoDB Overview"},
{_id : ObjectId("507f191e810c19729de860e2"), title: "NoSQL Overview"},
{_id : ObjectId("507f191e810c19729de860e3"), title: "Tutorials Point Overview"}
Following example will display the title of the file even as querying the file.
>db.mycol.find({},{"title":1,_id:0})
{"title":"MongoDB Overview"}
{"title":"NoSQL Overview"}
{"title":"Tutorials Point Overview"}
>
Please notice _id field is continually displayed whilst executing discover() technique, if you don't need this area, then you definately want to set it as 0.