title: How to group two or more fields using mongo aggregation to find the distincts
body: <p>My Appointment Document looks like this</p>
  <pre><code>[{
      &quot;_id&quot; : ObjectId(&quot;5f25686c946376355468caab&quot;),
      &quot;status&quot; : &quot;approved&quot;,
      &quot;slot&quot; : ObjectId(&quot;5ee751ab85596308c0272fa2&quot;),
      &quot;student&quot; : ObjectId(&quot;5eddc7d7cc5d3608c0393ce1&quot;),
      &quot;teacher&quot; : ObjectId(&quot;5eccfd6d4f5d8d48ac567a5d&quot;),
      &quot;cost&quot; : 49,
      &quot;createdAt&quot; : ISODate(&quot;2020-08-01T13:04:44.696Z&quot;),
      &quot;updatedAt&quot; : ISODate(&quot;2020-08-01T13:20:36.164Z&quot;),
      &quot;decisionTime&quot; : ISODate(&quot;2020-08-01T13:20:36.161Z&quot;)
  },
  {
      &quot;_id&quot; : ObjectId(&quot;5f25687b946376355468caac&quot;),
      &quot;status&quot; : &quot;approved&quot;,
      &quot;slot&quot; : ObjectId(&quot;5ee751ab85596308c0272fa3&quot;),
      &quot;student&quot; : ObjectId(&quot;5eddc7d7cc5d3608c0393ce1&quot;),
      &quot;teacher&quot; : ObjectId(&quot;5eccfd6d4f5d8d48ac567a5d&quot;),
      &quot;cost&quot; : 49,
      &quot;createdAt&quot; : ISODate(&quot;2020-08-01T13:04:59.125Z&quot;),
      &quot;updatedAt&quot; : ISODate(&quot;2020-08-01T13:06:12.289Z&quot;),
      &quot;decisionTime&quot; : ISODate(&quot;2020-08-01T13:06:12.288Z&quot;)
  },
  {
      &quot;_id&quot; : ObjectId(&quot;5f2ad883f0971a0c3c7d6e6f&quot;),
      &quot;status&quot; : &quot;approved&quot;,
      &quot;slot&quot; : ObjectId(&quot;5ee751ab85596308c0272fa4&quot;),
      &quot;student&quot; : ObjectId(&quot;5eddc7f4cc5d3608c0393ce3&quot;),
      &quot;teacher&quot; : ObjectId(&quot;5eccfd6d4f5d8d48ac567a5d&quot;),
      &quot;cost&quot; : 49,
      &quot;createdAt&quot; : ISODate(&quot;2020-08-05T16:04:19.437Z&quot;),
      &quot;updatedAt&quot; : ISODate(&quot;2020-08-05T16:04:52.616Z&quot;),
      &quot;decisionTime&quot; : ISODate(&quot;2020-08-05T16:04:52.615Z&quot;)
  }]
  </code></pre>
  <p>I want to group total number of distinct student, total number of appointment, total cost on a particular date(createdAt) using mongo aggregation.
  How do I get Distinct Student on a distinct Date</p>
  <p>Expected Output :</p>
  <pre><code>[
    {
      &quot;_id&quot;: &quot;01-08-2020&quot;,
      &quot;appointments&quot;: 2,
      &quot;totalCost&quot;: 98,
      &quot;totalStudents&quot;: 1
    },
    {
      &quot;_id&quot;: &quot;05-08-2020&quot;,
      &quot;appointments&quot;: 1,
      &quot;totalCost&quot;: 49,
      &quot;totalStudents&quot;: 1
    }
  ]
  </code></pre>
  <p>The problem here is that I want to find total number of distinct students</p>