Reputation: 12059
Is it possible to get an array of a specified fields value in mongodb?
Like instead of getting:
[{"color":"blue"},{"color":"red"}]
I would like to get:
["blue","red"]
Is this question clear enough?
Upvotes: 0
Views: 95
Reputation: 25091
You can run array.map
on the results array to achieve the desired result:
var colors = [{"color":"blue"},{"color":"red"}].map(function(obj){
return obj.color;
});
Upvotes: 1