问得好!
"多少是太多了?"-当然,这取决于数据大小和性能要求.一、 就个人而言,当我跳过超过500-1000条记录时会感到不舒服.
实际答案取决于你的要求.以下是现代网站(或者至少是其中一些网站)的功能.
首先,导航栏看起来像这样:
1 2 3 ... 457
他们从总记录数和页面大小中得到最终的页码.让我们跳到第三页.这将涉及从第一条记录中略过一些内容.当结果到达时,您知道第3页第一条记录的id.
1 2 3 4 5 ... 457
我们再跳过一些,转到第5页.
1 ... 3 4 5 6 7 ... 457
你明白了.在每个点上,您都可以看到第一页、最后一页和当前页,以及当前页的前后两页.
询问
var current_id; // id of first record on current page.
// go to page current+N
db.collection.find({_id: {$gte: current_id}}).
skip(N * page_size).
limit(page_size).
sort({_id: 1});
// go to page current-N
// note that due to the nature of skipping back,
// this query will get you records in reverse order
// (last records on the page being first in the resultset)
// You should reverse them in the app.
db.collection.find({_id: {$lt: current_id}}).
skip((N-1)*page_size).
limit(page_size).
sort({_id: -1});