Reputation: 5968
i am thinking of implementing a cursor based pagination and I think of encoding and decoding an id. is it possible to query like this in mongoose?
MyModel.find({ _id: 4 }).limit(10)
so basically after that id, you query for the next 10 items?
Upvotes: 3
Views: 399
Reputation: 4983
You can easily do it using
For Eg:
MyModel.find({ _id: 4 }).skip(0).limit(10)
MyModel.find({ _id: 4 }).skip(10).limit(10)
You can keep increasing the skip value by 10 and your pagination is done!
Read more: https://www.w3resource.com/mongodb/mongodb-skip-limit.php
Upvotes: 3