I have a model like this :
var field = {
createdAt: {type: Date, default: Date.now()},
updatedAt: {type: Date, default: Date.now()},
pic : {type: String, default: 'http://lorempixel.com/400/400/abstract/', writable: true},
thumb : {type: String, default: 'http://lorempixel.com/100/100/abstract/', writable: true},
name: {type: String},
description: {type: String},
isPublic: {type: Boolean, default: true},
members: [{type: Schema.Types.ObjectId, ref: 'Member'}],
}
Im using this code below to get the total count of the Member
's ID in members field.
Group.aggregate([
{$match: {_id:req.params.group_id}},
{$group: {
_id: '$members',
count: {$sum: 1}
}}
], function (err, count) {
res.send(count);
});
But it returns and empty array []
how do I get the proper count?
Thanks.