Pagination and sorting with _id

i have a quey where we were using pagination with skip and sorting the data with _id, but now when i am adding pagination with _id then the results are not accurate
e.g

Posts.find({_id: { "$lt": lastPageLastDocIdOFPrevReq }) .sort({ _id: -1 }).limit(15)
is there any problem with the query, or in case of sorting with _id: -1 we need to use skip overe here, which will be expensive i guess.

@sajan_kumar Please go through this link Mongodb Pagination

1 Like

How are they inacurate? What are the issues you faces?

my bad, the results are fine but I am not confident with the query that, is it going to work properly or not.