In MongoDB, projection means selecting only the required data rather than selecting whole document data. If a document has 5 fields and if you want to show only 3, then you have to select only 3 fields from them.
MongoDB's find() method, explained in MongoDB Query Document will accept second optional parameter which is a list of fields you wish to retrieve. In MongoDB, when find() method is executed, it will display all the fields of a document. To restrict this, you have to set a list of fields with value 1 or 0. 1 is used for showing the field and 0 is used for hiding the fields.
Basic syntax of find() method with projection is as follows
Consider collection mycol has below data
Below example will display the title of the document while querying the document.
Please note _id field is always displayed while executing find() method, if you don't need this field, then you have to set it as 0.
MongoDB Related Interview Questions
|Python Interview Questions||C & Data Structures Interview Questions|
|Hadoop Interview Questions||Node.js Interview Questions|
|Scala Interview Questions||Socket Programming Interview Questions|
|HBase Interview Questions||Solaris Administrator Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.