mongodb - 分片群集中的快速分页

时间:2017-11-08 01:48:06

标签: mongodb pagination sharding

我正在运行mongo 3.4(w / wiredtiger)。到目前为止,我一直在使用快速分页'以下文章(https://scalegrid.io/blog/fast-paging-with-mongodb)中指定的策略,即:

  
      
  1. 检索当前页面中最后一个文档的_id
  2.   
  3. 在下一页中检索大于此“_id”的文档
  4.   
//Page 1
db.users.find().limit(pageSize);
//Find the id of the last document in this page
last_id = ...

//Page 2
users = db.users.find({'_id'> last_id}). limit(10);
//Update the last id with the id of the last document in this page
last_id = ...

我即将对我的收藏进行分片以便允许水平缩放。作为启用分片的一部分,我将使用一个唯一的复合键(在字段" user_id"和" post_id")作为分片键。这将保证文档在分片之间的单一性,并且应该允许跨分片的相对良好的文档分发。

但是在我收集了我的收藏后,我能否使用上述快速分页策略?如果没有,是否有共同的解决方案?

由于

0 个答案:

没有答案