0

Lets say i have a users collection with 1000 documents like

{
  "_id": ObjectId("5923cef9421aa90aeafc3c0c"),
   name: "hariharasudhan",
   email: "test@gmail.com",
   "inserted_at" : ISODate("2017-05-23T05:56:09.501Z")
}

As a developer i would like to fetch 50 documents at each interval rather than going for 1000 documents at once, for example on each request from the user i would like to return 50 documents whose datetime $gt than ISODate("2017-05-23T05:56:09.501Z"), how to achieve this in mongo?

Hari
  • 1,545
  • 1
  • 22
  • 45
  • @Neil Lunn How implement the pagination based on sort by user name instead rank which u given in the [link](https://stackoverflow.com/questions/28105009/implementing-pagination-in-mongodb) – Hari May 25 '17 at 04:30
  • It's answered in the linked question. As you already note ( and so does the example ) you use the `$gt` like operations to select the "next page". Since it is possible for more than 1 document to have the same date/name/whatever, the other important thing is keeping a list of the primary keys ( `_id` ) which have already been seen. All explained in the linked answer. Read it and learn the process. So yes, you are still basically asking the same question as what is already answered. – Neil Lunn May 25 '17 at 04:41

0 Answers0