title: MongoDB, Multiple count (with $exists)
body: <p>I have these 3 requests:</p>
  
  <pre class="lang-js prettyprint-override"><code>db.mycollection.count({requestA:{$exists:true}})
  db.mycollection.count({requestB:{$exists:true}})
  db.mycollection.count({requestC:{$exists:true}})
  </code></pre>
  
  <p>I'd like to make only one request...
  So i tried the following:</p>
  
  <pre class="lang-js prettyprint-override"><code>db.mycollection.aggregate( [
      { $group: {
          '_id' : { user_id: '$user_id'},
          requestA_count: { $sum: {
              $cond: [ {requestA:{'$exists':true}}, 1, 0 ]
          } },
          requestB_count: { $sum: {
              $cond: [ {requestB:{'$exists':true}}, 1, 0 ]
          } },
          requestC_count: { $sum: {
              $cond: [ {requestC:{'$exists':true}}, 1, 0 ]
          } },
      } },
      { $project: {
          _id: 0,
          user_id: '$_id.user_id',
          requestA_count: 1,
          requestB_count: 1,
          requestC_count: 1
      } }
  ] );
  </code></pre>
  
  <p>But i got the error:</p>
  
  <pre class="lang-js prettyprint-override"><code>"errmsg" : "exception: invalid operator '$exists'",
  </code></pre>
  
  <p>I guess that we cannot use $exists with $project.</p>
  
  <p>Any tips about a good approach ? Thank you</p>