Easy Paging with offset
Paging is a common functionality for REST APIs. When implementing paging queries for large datasets skip and limit is often not an option. When using query filters with non unique fields, such as creation date there can be problems such as duplicate entities on subsequent pages. It would be great to be able to additionaly pass in an offset document reference, that would be used as a start in case the filter does not lead to a unique starting point.
so for example
db.test.find({"creationDate" : {$gte:ISODate('2021-08-27T07:25:00Z')}, {"offset":<ObjectId>).sort({"creationDate":1}).limit(20)
![](https://secure.gravatar.com/avatar/6f88ff298217c556150114db33713bfc?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)
-
Could you expand on this a little, why would this be preferred over adding a filter on unique field, e.g.
db.test.find({"creationDate" : {$gte:ISODate('2021-08-27T07:25:00Z')}, "_id" : {$gte: lastSeenId}).sort({"creationDate":1, _id: 1}).limit(20)