title: How to aggregate and fetch a record from MongoDB?
body: <p>I am learning MongoDB queries and try to do aggregation.
  In case if I have list of records like below:</p>
  <pre><code>{ _id: 1, cust_id: &quot;abc1&quot;, ord_date: ISODate(&quot;2012-11-02T17:04:11.102Z&quot;), status: &quot;A&quot;, amount: 50 }
  { _id: 2, cust_id: &quot;xyz1&quot;, ord_date: ISODate(&quot;2013-10-01T17:04:11.102Z&quot;), status: &quot;A&quot;, amount: 100 }
  { _id: 3, cust_id: &quot;xyz1&quot;, ord_date: ISODate(&quot;2013-10-12T17:04:11.102Z&quot;), status: &quot;D&quot;, amount: 25 }
  { _id: 4, cust_id: &quot;xyz1&quot;, ord_date: ISODate(&quot;2013-10-11T17:04:11.102Z&quot;), status: &quot;D&quot;, amount: 125 }
  { _id: 5, cust_id: &quot;abc1&quot;, ord_date: ISODate(&quot;2013-11-12T17:04:11.102Z&quot;), status: &quot;A&quot;, amount: 25 }
  </code></pre>
  <p>Then if I want to group above records based on <code>status</code> and need to fetch record based on maximum <code>amount</code>
  So I need two records output from above collections:</p>
  <p><code>_id:2</code> should be fetched from <code>status: A</code> and same way <code>_id:4</code> should be fetched from <code>status:D</code> group.
  Is there a way to do this?</p>
  <p>I have gone through example queries in sample, they are grouping and calculating sum or average, so how we can achieve this.</p>