• 请不要在回答技术问题时复制粘贴 AI 生成的内容
audestick
V2EX  ›  程序员

mongodb skip500w 的数据超时

  •  
  •   audestick ·
    audeSt · Sep 15, 2016 · 3323 views
    This topic created in 3701 days ago, the information mentioned may be changed or developed.

    如题

    collection.find({}, config.fields).skip(i * config.batch_size + 5840000 ).limit(config.batch_size).toArray
    

    文档中没有递增的,可以区分所有数据的字段,不然可以 where+limit 做分页

    同志们怎么解决这个问题?

    gouchaoer
    gouchaoer
    Sep 15, 2016 via Android
    1
    诀窍就是插入数据的时候用 count (*)的结果作为自增字段并且加上索引。。。。因为 mongo 的 count (*)复杂度为常数,自增字段可能有重复但是不影响最后遍历数据的时候用索引的区间查找
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2764 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:50 · PVG 21:50 · LAX 05:50 · JFK 08:50
    ♥ Do have faith in what you're doing.