title: count of $lookup result mongodb
body: <p><strong>Using mongodb with NodeJS driver</strong></p>
  <p>I have 2 collections. One for department and other for students.</p>
  <p>Sample data for Deparmtent.</p>
  <pre><code>{ 
   &quot;_id&quot; : ObjectId(&quot;5a24d20590d3d12155f3094e&quot;), &quot;name&quot; : &quot;CSE&quot;, &quot;hod&quot; : 
   &quot;abc&quot;, 
   &quot;students&quot; : [ 
    ObjectId(&quot;5a2129172c3e542acb78c1f5&quot;),
    ObjectId(&quot;5a2129172c3e542acb78c1f7&quot;), 
    ObjectId(&quot;5a2129172c3e542acb78c1f9&quot;), 
    ObjectId(&quot;5a2129172c3e542acb78c1fb&quot;)
   ]
  }
  
  {
   &quot;_id&quot; : ObjectId(&quot;5a24d20590d3d12155f3094f&quot;), 
   &quot;name&quot; : &quot;IT&quot;, 
   &quot;hod&quot; : &quot;xyz&quot;, , 
   &quot;students&quot; : [ 
    ObjectId(&quot;5a2129172c3e542acb78c1f6&quot;),
    ObjectId(&quot;5a2129172c3e542acb78c1f8&quot;), 
    ObjectId(&quot;5a2129172c3e542acb78c1fa&quot;),
    ObjectId(&quot;5a2129172c3e542acb78c1fc&quot;) 
   ] 
  }
  </code></pre>
  <p>and sample data for Students</p>
  <pre><code>{
      &quot;_id&quot; : ObjectId(&quot;5a2129172c3e542acb78c1f4&quot;),
      &quot;rollNumber&quot; : 11,
      &quot;name&quot; : &quot;Thor&quot;,
      &quot;branch&quot; : ObjectId(&quot;5a24d20590d3d12155f3094e&quot;),
  }
  </code></pre>
  <p>Here is the query:</p>
  <pre><code>aggregate([
     {$lookup: 
       { from: &quot;students&quot;, 
         localField: &quot;_id&quot;, 
         foreignField: &quot;branch&quot;,
         as: &quot;studentData&quot;
       }
     }
  ])
  </code></pre>
  <p>Output of the query</p>
  <pre><code>[ 
    { _id: 5a24d20590d3d12155f3094e,
      name: 'CSE',
      hod: 'abc',
      studentData: [ [Object], [Object], [Object], [Object], [Object] ] 
    },
    { _id: 5a24d20590d3d12155f3094f,
      name: 'IT',
      hod: 'xyz',
      studentData: [ [Object], [Object], [Object], [Object] ] } 
  ]
  </code></pre>
  <p>I have two questions</p>
  <ol>
  <li>How to print complete student data.</li>
  <li>How to get the count of studentData for each Department</li>
  </ol>