title: MongoDB needs to get total counts from all objects
body: <p>my aggregate query looks like this. I need to get the total count from the value.</p>
  <pre><code>db.getCollection('mydesk').aggregate([
  {
      $match: {
          &quot;accountId&quot;: ObjectId(&quot;616ea615edc5fa4278ccb7f6&quot;),
                  &quot;val&quot; : { $ne : null},
          &quot;deskId&quot;: { &quot;$in&quot;: [ 
                  ObjectId(&quot;61934f7efdb9dc5a7c1c3a01&quot;), 
                  ObjectId(&quot;61713730857c3243ec1d257c&quot;), 
                  ObjectId(&quot;629d9548e0c93e34e435e7b9&quot;), 
                  ObjectId(&quot;616eaf613bcd9655b8035a25&quot;), 
              ]}
      }
  },
  {
        $project: {
           item: 1,
           value:  { $size: &quot;$val.shapes&quot; },
        }
  }
  
  ])
  </code></pre>
  <p>I got result like this. But need to get the total counts of my value.</p>
  <pre><code>/* 1 */
  {
      &quot;_id&quot; : ObjectId(&quot;616fab4f12b90d59d03f380e&quot;),
      &quot;value&quot; : 11
  }
  
  /* 2 */
  {
      &quot;_id&quot; : ObjectId(&quot;616fbad35700980a041cd190&quot;),
      &quot;value&quot; : 4
  }
  
  /* 3 */
  {
      &quot;_id&quot; : ObjectId(&quot;61713752857c3243ec1d257e&quot;),
      &quot;value&quot; : 12
  }
  </code></pre>
  <p>Needed result :</p>
  <pre><code>{
      &quot;totalValueCount&quot; : 27
  }
  </code></pre>
  <p>Thanks in advance</p>