Mongodb Aggregation How to get total count

395 views
Skip to first unread message

goutham gowda

unread,
Dec 22, 2015, 10:19:07 PM12/22/15
to mongodb-user
For this below query, 
db.profileInterest.aggregate([
   { $project: { _id: 1, fromProfile: 1, toProfile: 1, contactNoViewed:1, shortListed: 1, count: {$size: '$interestStatus'}, threeFavorites: { $slice: [ "$interestStatus", -1 ] }} },
   {$match: {"threeFavorites.id": {$ne: 100}, total:{$size: '$fromProfile'}}}
]).pretty();

how to get total count of this aggregation.

Hakan

unread,
Dec 23, 2015, 3:54:48 AM12/23/15
to mongodb-user
You can use itcount()::: 

db.profileInterest.aggregate([ ..... ]).itcount();

or

make another group stage::

db.profileInterest.aggregate([ ......., {$group: {_id: null, total: {$sum:1 }}}]);
Reply all
Reply to author
Forward
0 new messages