title: $sort invalidates $skip in aggregation pipeline mongodb
body: <p>I'm using aggregation to query users. Each subsequent request uses $skip to get the next set of results as follows.</p>
  
  <pre><code>var aggPipeline = [
    locationMatch,
    userToUsersMatch,
    usersToUserMatch,
    {
      $skip:cursor
    },
    {
      $limit:perRequest
    } 
  ]
  </code></pre>
  
  <p>This works fine and returns users until there are none left to return. When I add a $sort into the pipeline the $skip seems to stop working and repeat data is returned in each subsequent request (even though the cursor/offset is incrementing).</p>
  
  <pre><code>aggPipeline = [
    locationMatch,
    userToUsersMatch,
    usersToUserMatch,
    {
      $sort:{lastActive:-1}
    },
    {
      $skip:cursor
    },
    {
      $limit:perRequest
    }
  ]
  </code></pre>
  
  <p>I'm attempting to sort all the results by the lastActive field and then return them, skipping the offset as to what has already been returned. I can't understand why $sort causes repeat data to be returned in subsequent calls - it is not always exact repeat from the previous request but may append a user every so often and remove the first user.</p>
  
  <p>Anyone know what is happening here?</p>
  
  <p>Many thanks.</p>