【问题标题】:how to read data from mongodb block by block and write to posrgres如何逐块从mongodb读取数据并写入postgres
【发布时间】:2018-11-22 09:45:58
【问题描述】:

我有一个在生产中运行的 mongo db。我想将数据从 MongoDB 移动到 Postgres 以满足某些迁移要求。

现在谈到数据部分,我打算编写一个实用程序,它将从 MongoDB 读取数据并写入 Postgres。

在这里,我想将所有数据从 mongo db(包含 240335 行)读取到 Postgres。

我无法将整个数据读入应用程序的内存中。我想批量读取 10000,然后写入做一些修改并将其写入 Postgres,然后再次读取下一个 10000,再次重复此操作。

我该怎么做?

【问题讨论】:

    标签: java mongodb postgresql spring-boot


    【解决方案1】:

    我从来没有做过,但我认为,您可以使用游标分别上传记录。 问题 - 解决方案效率低下。

    例子

    var myCursor = db.bios.find( );
    var myDocument = myCursor.hasNext() ? myCursor.next() : null;
    
    if (myDocument) {
        var myName = myDocument.name;
        print (tojson(myName));
        //put record to db or add to batch, and upload if 1000 in collection
    }
    

    也许您可以使用流?不知道 MongoDB 中是否可以使用流。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-18
      • 1970-01-01
      • 2020-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-12
      • 1970-01-01
      相关资源
      最近更新 更多