title: Sorting with condition in mongodb
body: <p>Here is the example collection:</p>
  
  <pre><code>[
   {'name': 'element1', ratings: {'user1': 1, 'user2':2}},
   {'name': 'element2', ratings: {'user1': 2, 'user2':1}}
  ]
  </code></pre>
  
  <p>I want to sort for user1:  ['element2', 'element1'] ,
  and for user2: ['element1', 'element2'].</p>
  
  <p>In other words, I want to place the results with maximum rating for current user to top. </p>
  
  <p>The collection is very big, thats why search must use indexes. The collection structure can be modified, this is just example.   </p>