title: Mongodb query equivalent of the following SQL query
body: <p>I have a table as UserData which has strucure like</p>
  
  <pre><code> id category    value
   1  AR          100
   2  WT          90
   3  WT          12
   4  AR          1000
   5  AR          2005
   6  WT          122
   7  BP          112
   8  BP          18
  </code></pre>
  
  <p>now  I want to select all rows which has maximum  value in the indiviual category. so my result set should be.</p>
  
  <pre><code>id  category    value   
  5   AR          2005    
  6   WT          122     
  7   BP          112 
  </code></pre>
  
  <p>I want to have this in MongoDB  query.</p>
  
  <p>It`s sql equivalent is this one</p>
  
  <pre><code>     select id,category,value from
          (select id,
                  category,
                  value,
                  max(value)
          over (partition by category) result
          from   UserData ) a 
         where a.result=a.value order by a.id
  </code></pre>
  
  <p>I want to know that How can I produce same result in the MongoDB query</p>