If you want to get the "next page" or "previous page", you can do it by querying sort+limit that is greater than a certain _id.
If you want to get "page xxx", if you want to be completely accurate, there is actually no good way. The paging itself is a "count one by one" logic, and this time-consuming process cannot be avoided regardless of whether there is an index.
When the number of pages is very large, not many people care about the numbers after tens of millions. You can use redis to cache the _id list by page number and update it every once in a while.
The fundamental point of this problem is: "The b+ structure on which the index relies cannot be used for ranking calculations."
If you want to get the "next page" or "previous page", you can do it by querying sort+limit that is greater than a certain _id.
If you want to get "page xxx", if you want to be completely accurate, there is actually no good way. The paging itself is a "count one by one" logic, and this time-consuming process cannot be avoided regardless of whether there is an index.
When the number of pages is very large, not many people care about the numbers after tens of millions. You can use redis to cache the _id list by page number and update it every once in a while.
The fundamental point of this problem is: "The b+ structure on which the index relies cannot be used for ranking calculations."
Record the last _id of the last query, and the next query will be {_id: {$gt: last_id}}