thedog
V2EX  ›  问与答

Python 遍历 mongodb 时,如何保存游标位置到本地

  •  
  •   thedog · Apr 13, 2018 · 2224 views
    This topic created in 2963 days ago, the information mentioned may be changed or developed.
    项目中遇到一个需求,需要将一个千万条记录级别的 mongodb 库提取部分字段转到 postgresql 中。
    由于 mongodb 一直在更新,所以每隔一段时间就需要倒一次数据。所以想实现增量更新的功能。
    问题是,我要如何保存上一次 python 遍历到的位置?

    ps:mongodb 的_id 字段是自动生成的,其他字段无严格的递增或递减的数量关系。
    baichi
        1
    baichi  
       Apr 14, 2018
    find_filter = {
    "_id":{"$gt": ObjectId( last_id )}
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1075 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:04 · PVG 02:04 · LAX 11:04 · JFK 14:04
    ♥ Do have faith in what you're doing.