Question : mongodb select specific fields
Answered by : sleepy-starling-rty94if0476x
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
Source : https://stackoverflow.com/questions/25589113/how-to-select-a-single-field-for-all-documents-in-a-mongodb-collection | Last Update : Mon, 14 Dec 20
Question : mongodb select fields
Answered by : annoying-ant-chd232fwd9wi
db.inventory.find( { status: "A" }, { item: 1, status: 1 } )
Source : https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results | Last Update : Thu, 01 Oct 20
Question : mongodb projection example
Answered by : annoyed-antelope-87f5ykzp3ikm
{ $project: { "field1": 0, "field2": 1, ... } }
Source : https://docs.mongodb.com/manual/reference/operator/aggregation/project/ | Last Update : Mon, 12 Apr 21
Question : projection in mongodb
Answered by : abhiiii
Projection in mongoDB :
-> You can select the field you want in query to return
-> if you want field use {"field":1}
-> _id field is compasary if you dont want it use {"_id":0}
db.users.find({},{name:1,email:1, id:0}).pretty();
Source : | Last Update : Sat, 23 Apr 22