title: MongoDB sort all and get specific range
body: <p>I'm using mongoDB. I have a collection with:</p>
  
  <pre><code>String user_name,
  Integer score
  </code></pre>
  
  <p>I would like to make a query that gets a user_name. The query should be sorted by score which returns the range of the 50 documents which the requested user_name is one of them.</p>
  
  <p>For example, if I have 110 documents with the user_name X1-X110 with the scores 1-110 respectively and the input user_name was X72 I would like to get the range: X51-X100</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>An example of 3 documents: </p>
  
  <pre><code>{ "user_name": "X1", "score": 1}
  { "user_name": "X2", "score": 2}
  { "user_name": "X3", "score": 3}
  </code></pre>
  
  <p>Now if I have 110 documents as described above, and I want to find X72 I want to get the following documents:</p>
  
  <pre><code>{ "user_name": "X50", "score": 50}
  { "user_name": "X51", "score": 51}
  ...
  { "user_name": "X100", "score": 100}
  </code></pre>
  
  <p>How can I do it?</p>
  
  <p><strong>Clarification:</strong> I don't have each document rank stored. What I do have is document scores, which aren't necessarily consecutive (the example is a little bit misleading). Here's a less misleading example:</p>
  
  <pre><code>{ "user_name": "X1", "score": 17}
  { "user_name": "X2", "score": 24}
  { "user_name": "X3", "score": 38}
  </code></pre>
  
  <p>When searching for "X72" I would like to get a slice of size 50 in which "X72" resides according to its rank. Again, the rank is not the element score, but the element index in a hypothetical array sorted by scores.</p>