title: How to remove duplicate objects with different parameters in an aggregation in mongo db
body: <pre class="lang-js prettyprint-override"><code>[
     { id:1,month:5,year:2020,text:&quot;Completed&quot; },
     { id:2,month:2,year:2021,text:&quot;Pending&quot; },
     { id:3,month:3,year:2020,text:&quot;Completed&quot; },
     { id:4,month:5,year:2020,text:&quot;Pending&quot; },
     { id:5,month:4,year:2022,text:&quot;Pending&quot; },
  ]
  </code></pre>
  <p>These are the documents in my collection. I need to remove remove the duplicate objects with same year &amp; month using aggregation in mongo db. so that i get</p>
  <pre class="lang-js prettyprint-override"><code>[
     { id:1,month:5,year:2020,text:&quot;Completed&quot; },
     { id:2,month:2,year:2021,text:&quot;Pending&quot; },
     { id:3,month:3,year:2020,text:&quot;Completed&quot; },
     { id:5,month:4,year:2022,text:&quot;Pending&quot; },
  ]
  </code></pre>