MongoDB Projections
In MongoDB, projection means selecting only the necessary data rather than selecting all document fields.
Syntax of Projections
db.collection.find({}, {KEY:1 or 0});
Here, the KEY is the field and we can set its value either 1 or 0. If we want to hide the field from result data, then set it to 0 and if we want to show the data, set it to 1. By this, we can control on the find() method and fetch only the required data.
Example
Suppose we have the following students data.
If we need to hide the age field, run the following query -
db.students.find({}, {age:0});