Mongo DB projection – Get the necessary data

In MongoDBprojection means selecting only the necessary data rather than selecting the whole of the data of a document collection. Explained with example. Learn how to use Projection in MongoDB Query to get the selected fields of documents in the output.

Projection is displays data that is useful or filter data and gets the usable one. Removal of unnecessary data from the document 

0:do not show

data1:show data 

db.customers.find({},{name:1,age:0,_id:0})

e do not need to write age:0 as above as we write age only . otherwise it will showing error

We should write age only when want to retentive data

db.customers.find({},{name:1,age:1,_id:0})

 now we get both age and name as below

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

codeforbetter will use the information you provide on this form to be in touch with you and to provide updates and marketing.