title: MongoDB best practice to count related documents
body: <p>I was wondering what is the best practice to get a count of related documents of a particular document in MongoDB.</p>
  
  <p>Scenario is as follows:
  I need to get posts that users shared and I need to get total number of comments related to those posts as well.</p>
  
  <p>I would like to use the MongoDB Aggregation way if possible (if that is the best way of doing it)
  I am aware how to perform this query using separate methods .count() and .find().</p>
  
  <p>document in posts collection:</p>
  
  <pre><code>{
      _id: ObjectId('5a66321e7e2043078bc3b88a'),
      uid: 'UniqueIDofTheUser',
      text: 'Post text'
  }
  </code></pre>
  
  <p>document in comments collection</p>
  
  <pre><code>{
      _id: ObjectId('5a66321e7e2043078bc3b88c'),
      uid: 'UniqueIDofTheUser',
      post_id: ObjectId('5a66321e7e2043078bc3b88a'),
      text: 'Comment text'
  }
  </code></pre>
  
  <p>Desired Result:</p>
  
  <pre><code>[
      {
          _id: ObjectId('5a66321e7e2043078bc3b88a'),
          uid: 'UniqueIDofTheUser',
          text: 'Post text',
          commentsCount: 20
      },
      {
          _id: ObjectId('5a66321e7e2043078bc3b88c'),
          uid: 'UniqueIDofTheUser',
          text: 'Another post',
          commentsCount: 3
      },
      {
          _id: ObjectId('5a6632e17e2043078bc3b88f'),
          uid: 'UniqueIDofTheUser',
          text: 'Some random post',
          commentsCount: 4
      },
  ]
  </code></pre>