mongoDB有没有快速翻页的方法?
漂亮男人
漂亮男人 2017-05-02 09:17:50
0
1
682

翻页是采用limit 加上find 第一页的最后一条的_id 来取出第二页的内容

但是就算把索引都载入内存后 翻过两千万文档后每次翻页都耗时十秒以上

请问还有什么翻页快速的方法么

拜谢 感激不尽

漂亮男人
漂亮男人

reply all(1)
世界只因有你

First get the first id of the current page, and then use the following to get all the data of the next page:

db.collection.find({_id: {$gt: current_id}}).
              skip(page_size).
              limit(page_size).
              sort({_id: 1});

I have more than 6 million pieces of data, and it is very fast to use this method.
If this is the case for you and it still takes more than ten seconds, it may be that your query conditions are not indexed.


Use skiplimit to turn pages

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!