title: MongoDB use position in sorted query result to compute field
body: <p>I have a Mongoose Model for users. Each user has a certain amount of points. I'd like to create a field that is the users rank where:</p>
  
  <pre><code>rank = user position sorted by rank / total users
  </code></pre>
  
  <p>Let's suppose the user model looks like this:</p>
  
  <pre><code>{
      'name': 'bob',
      'points': 15,
      'rank': 9/15,
  }
  </code></pre>
  
  <p>(I realize that the fraction would really be a decimal when stored).</p>
  
  <p>Is there a way that I can update all of these users by:</p>
  
  <p>1) Sorting them by points</p>
  
  <p>2) Get a user's index in this sorted list</p>
  
  <p>3) Divide that index by the total number of items in the list</p>
  
  <p>I'm not sure what kind of mongo operators are out there for finding a doc's position in query results and for finding the total size of the query results.</p>