user938541
user938541

Reputation:

mongodb retrieve one field from every document into array

I would like to get one field from the selected documents but I want all of the values to be in a simple array.

users.find({}, ['regid'], function(err, docs){
    //console.log(docs);
});

should return:

['reg1','reg2',...]

Thank you

Upvotes: 0

Views: 40

Answers (1)

tymeJV
tymeJV

Reputation: 104775

You can do:

users.find({}, {'regid' : 1}).toArray(function(err, docs){
    //console.log(docs);
});

Upvotes: 1

Related Questions