MongoDB Projection
MongoDB gives an extraordinary element that is known as Projection. It permits you to choose just the vital information instead of choosing entire information from the record. For instance, a report contains 5 fields, for example
{
name: "Roma",
age: 30,
branch: EEE,
department: "HR",
salary: 20000
}
Yet, we just need to show the name and the age of the worker as opposed to showing entire subtleties. Presently, here we use projection to show the name and age of the representative.
One can utilize projection with db.collection.find(>
technique. In this strategy, the subsequent boundary is the projection boundary, which is utilized to indicate which fields are returned in the matching reports.
Syntax:
technique doesn't uphold following projection administrators, i.e., $, $elemMatch, $slice, and $meta.
strategy generally return _id except if you set a _id field to 0.
Examples:
In the following examples, we are working with:
Database: GeeksforGeeks
Collection: employee
Document: five documents that contain the details of the employees in the form of field-value pairs.
Displaying the names of the employees
Displaying the names of the employees without the _id field –
Displaying the name and the department of the employees without the _id field
Displaying the names and the department of the employees whose joining year is 2018