how to use aggregate for group and count in mongoose?
<p>I have json object in my db like as follows:</p>

<pre><code>{
'name':'test1',
'game':'cric'
},

{
'name':'test1',
'game':'cric'
},

{
'name':'test1',
'game':'football'
},

{
'name':'test2'
'game':'football'
}
</code></pre>

<p>I am trying to get output as follows</p>

<pre><code> {
    'name':'test1'
    'game':[{cric: 2}, {football:1}],
    'totalCount': 3
    }
</code></pre>

<p>I used aggregate query for that. </p>

<pre><code>group {'_id':{name:'$name'}, {game:{$addToSet:$game}}
project {name : $name, game: $game}
</code></pre>

<p>I got output as </p>

<pre><code>{name: 'test1', 'game':[cric, football]}
</code></pre>

<p>Now i have question that, how can i get count of game. it current example for cricket it is 2 and for football 1 for test1 user</p>