Node.js node/postgres-从STDIN结果复制不完整。没有抛出异常
我正在使用将数据从mongodb批量导入到Node.js node/postgres-从STDIN结果复制不完整。没有抛出异常,node.js,mongodb,postgresql,postgresql-copy,Node.js,Mongodb,Postgresql,Postgresql Copy,我正在使用将数据从mongodb批量导入到postgresql db 我使用observables映射从mongodb传入的数据,然后将其写入copyFrom正在使用的流。大致如下: function writeToStream (source, stream) { const trigger = Rx.Observable.fromEvent(stream, 'drain') hotsource = source.publish() const sub = trigger
postgresql db
我使用observables映射从mongodb传入的数据,然后将其写入copyFrom正在使用的流。大致如下:
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)
使用调试器工具,我可以看到每个文档都正确地映射并写入到流中
脚本运行时不会出现问题,并且在结束时不会引发任何异常。尽管如此,当我检查postgres db的结果时,行数比预期的少有人知道为什么会发生这种情况吗?
注意:脚本将几个mongo集合导入postgres表,但其中只有两个存在此问题。此外,这两个集合中的行数始终相同
注二:此代码为简化版本。原始脚本处理并发性和其他潜在问题,我认为这些问题与此问题无关
**编辑:**我已将postgres配置为将日志保存到文件中。文件中的日志也没有显示任何错误