In my MongoDB, I have a student collection with 10 records having fields name
and roll
. One record of this collection is:
{
\"
Using Studio 3T for MongoDB, if I use .find({}, { _id: 0, roll: true })
it still return an array of objects with an empty _id
property.
Using JavaScript map
helped me to only retrieve the desired roll
property as an array of string:
var rolls = db.student
.find({ roll: { $gt: 70 } }) // query where role > 70
.map(x => x.roll); // return an array of role