title: Cursor based pagination in MongoDB with sorting on 2 properties
body: <p>My end goal is to implement cursor based pagination in MongoDB, while sorting on 2 properties.</p>
  
  <p>Suppose we have the following collection:</p>
  
  <pre><code>+--------------------------------------+------+-------+
  |                 _id                  | cost |  vip  |
  +--------------------------------------+------+-------+
  | ObjectId("5dae005e665fc34b03c70f8a") |  700 | true  | &lt;-- first query
  | ObjectId("5dae005e665fc34b03c70f8c") |   50 | true  | &lt;-- first query
  | ObjectId("5dae005e665fc34b03c70f88") |    1 | true  | &lt;-- second query
  | ObjectId("5dae005e665fc34b03c70f8b") | 1200 | false | &lt;-- second query
  | ObjectId("5dae005e665fc34b03c70f87") |  400 | false |
  | ObjectId("5dae005e665fc34b03c70f89") |  300 | false |
  +--------------------------------------+------+-------+
  </code></pre>
  
  <p>And we want the result sorted: <code>{vip: -1, cost: -1}</code>, with a limit of 2. The first query would return row 1 &amp; 2, with the end-cursor being (ObjectId("5dae005e665fc34b03c70f8c")).</p>
  
  <p>With this info, how do I fetch the next 2 rows (i.e. row 3 + 4)?</p>
  
  <p>I have tried with the following filter, but to no help.</p>
  
  <pre><code>{_id: {$lt: ObjectId('5dae005e665fc34b03c70f8c')}, cost: {$gt: 1}}
  </code></pre>
  
  <p>Thanks for your help.</p>