These are chat archives for Automattic/mongoose

12th
Jul 2016
Mohamed Nasrullah
@nasr18
Jul 12 2016 06:55
i will get an array of object data and in that a field named count. how do i get sum of all that count.
Mohamed Nasrullah
@nasr18
Jul 12 2016 08:02
{ "_id" : ObjectId("512bc95fe835e68f199c8686"), "product" : "watch", "count" : 5 }
{ "_id" : ObjectId("512bc962e835e68f199c8687"), "product" : "mobile", "count" : 3 }
{ "_id" : ObjectId("512bc962e835e68f199c8686"), "product" : "watch", "count" : 2 }
how do i get sum of count of a particular product???
Andrew Newdigate
@suprememoocow
Jul 12 2016 12:08
@nasr18 use an aggregation:
Model.aggregate([
  { $match: { product: 'watch' } },
  { $group: { _id: 1, total: { $sum: "$count" } } }
])
Mohamed Nasrullah
@nasr18
Jul 12 2016 12:09
yeah i did. Actually its my mistake.
but now fixed it. thanks for your reply
Mohamed Nasrullah
@nasr18
Jul 12 2016 15:47
populate returning null dont know whats the issue.
Marko Bolliger
@cannap
Jul 12 2016 16:36
hi
is this the right way to do multiple updates http://laravel.io/bin/7wvXv
i have a sortable list and when i make new order
i send all _id from the client in the new order
Looks then something like this ["57851b77383ec20033acc351", "57851b67383ec20033acc350"]
Alex Shpak
@ishikawayoshi
Jul 12 2016 19:33
@cannap i update multiple entries smth like
arrayOfId = ['id1','id2'];
Model.update({'_id':{$in: arrayOfId}},{$set:{paid:true}}, { multi: true }, function (err, doc){
    if(err){
        console.log(err);
    }
    console.log('All is ok');
});
Marko Bolliger
@cannap
Jul 12 2016 20:19
k
yea @ishikawayoshi but i need the index
for the order