mongodb find and select fields code example
Example 1: mongodb select specific fields
db.student.find({}, 'roll _id'); // <--- Just multiple fields name space separated
// OR
db.student.find({}).select('roll _id'); // <--- Just multiple fields name space separated
// OR
db.student.find({}, {'roll' : 1 , '_id' : 1 ); // <---- Old lengthy boring way
Example 2: mongodb select fields
db.inventory.find( { status: "A" }, { item: 1, status: 1 } )
Example 3: how to project specific field mongodb nodejs
db.inventory.find( { status: "A" }, { item: 1, status: 1 } )
//1 to show and 0 to hide
//_id always included need to be set to 0 if not needed