Reputation: 322
I am using Mongoose to query my User schema, which contains:
var usersSchema = new Schema(
{
email : String,
regId : { type : String , default : '' },
lastName : { type : String , default : '' },
...
});
I need to get getId
property values for the array of emails i have. Currently i am trying to do:
db.model('users').find( { email : { $in : arrUsers } }, { regId : true, _id : false }, function (err, res) { ... }
I receive this array: [{ regId : "..." }, { regId : "..." }]
.
What i want to receive: { "...", "..." }
.
Is there an easy way to do this? Thanks a lot !!!
EDIT: I am interested in doing the for loop on the database side...
Upvotes: 1
Views: 4099
Reputation: 1220
You can use additional underscores map function:
var regIds = _.map(res, function (element) {
return element.regId;
});
//regIds = ['..', '..'] as you've expected
Upvotes: 4