亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

MongoDB中數(shù)據(jù)量大的話,不推薦使用 skip 和 limit,那其它方式怎么實現(xiàn)?
迷茫
迷茫 2017-04-24 09:10:31
0
2
738
  1. 如題,我前兩天去參加 MongoDB 用戶組交流會時,聽講師說到數(shù)據(jù)量大的話不要使用 skip 和 limit
    因為,這樣會一行一行的數(shù)到想到的頁數(shù)再取 PageSize 的數(shù)量。當然他們也提了另外一個方法,但是只略講了一句。

    我在這里提問是想知道具體怎么做?求思路。

迷茫
迷茫

業(yè)精于勤,荒于嬉;行成于思,毀于隨。

reply all(2)
大家講道理

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."

Ty80

Record the last _id of the last query, and the next query will be {_id: {$gt: last_id}}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template