am using mapfunction in my code i would like to pring Qdata of below array but here it says undefined may be it is inside the array of json if am wrong please help me to correct this!
my array structure is like this
[ { _id: 201,
user_id: 141,
PAN: 1,
Qdata: 023444 } ]
here is the map fun:
var data = array.map(function(p){
return p.Qdata
})
My actual code:
function getTotal(req, res, next) {
var array = [];
var array2 = {};
db.users.find(req.q).toArray(function(err, rest) {
rest.map(function(ids) {
array.push(ids._id);
})
var total = array.length;
for (var i = 0; i < array.length; i++) {
db.users.find(array[i]).toArray(function(err, users) {
if (err) return next(err);
});
db.consumer.aggregate([{
$unwind: "$votes"
}, {
$match: {
'consumer_id': mongoskin.helper.toObjectID(array[i])
}
}, {
$group: {
_id: "$votes.date",
"consumer_id": {
$first: "$consumer_id"
},
"vote": {
$sum: {
$cond: [{
'$gt': ['$votes.score', 0]
}, "$votes.score", 0]
}
}
}
}], function(err, sort_res) {
array2.push(sort_res);
total -= 1;
if (total <= 0) {
var user_obj = {};
for (var i = rest.length - 1; i >= 0; i--) {
var userDetails = rest[i];
user_obj[userDetails._id] = userDetails;
}
var aa=array2.map(function(p){
p.userDetails = obj[p.consumer_id];--------> here am not getting consumer_id
return p
})
res.send(aa)
}
})
}
})
}
_idproperty, and an end paranthesis after the last } in your second code.023444).undefinefor me :(