节点/ postgres – 从STDIN结果复制不完整。 没有例外被抛出

我使用node-pg-copy将数据从mongodb批量导入到postgresql db

我使用observables来映射从mongodb进来的数据,然后将其写入到copyFrom正在使用的stream中。 有些东西是:

 function writeToStream (source, stream) { const trigger = Rx.Observable.fromEvent(stream, 'drain') hotsource = source.publish() const sub = trigger .takeUntil(hotSource.last()) .subscribe( data => stream.write(String(data)) && pauser.next(true), // pauser gets the next row to deal with concurrency. Using debugger, I can see that 'data' is ok every time. err => stream.emit('error', err), () => !stream._isStdio && stream.end() ) sub.add(hotsource.connect()) } const textSource = Rx.Observable.from(docs) .map(doc => toTextFormat(doc)) // using debugger tools, I can see that every document passes through this method, and returns ok. const copyStream = pgClient.query(copyFrom( `COPY "${table}" (${columnNames.join(', ')}) FROM STDIN` )) const subscription = writeToStream(textSource, copyStream) 

使用debugging工具,我可以看到每个文档都被正确地映射并写入到stream中。

该脚本运行没有问题,并没有抛出任何exception完成。 从来没有那么less,当我检查postgres数据库的结果,有比预期less的行。 有人知道为什么会发生这种情况?

注意:脚本将几个mongo集合导入到postgres表中,但是只有两个有这个问题。 而且,这两个集合中的行数总是相同的。

注二:这个代码是一个简化版本。 原来的脚本处理并发和其他潜在的问题,我认为是不相关的这个问题。

**编辑:**我已经configurationpostgres将日志保存到文件。 文件中的日志也不显示任何错误。