Raf*_*Mor 3 cassandra node.js datastax-enterprise datastax datastax-node-driver
我使用 Cassandra 和 Node.js 来通过 everyRow 获取大表。
我需要在每一行上插入数据,但由于某种原因,它没有等待查询并且在完成之前完成。
client.eachRow(query, [], { prepare: true, autoPage : true, fetchSize: 500 }, function(index, row) {
// DB query / insert or update
, function(err, result) {
// Finish all rows.
});
Run Code Online (Sandbox Code Playgroud)
有什么建议么?
只需浏览官方 cassandra-driver 文档https://www.npmjs.com/package/cassandra-driver并找出这一行
#stream() 方法以相同的方式工作,但它不是回调而是返回 objectMode 中的 Readable Streams2 对象,该对象发出 Row 的实例。
client.stream(query, [ 'abc' ])
.on('readable', function () {
// 'readable' is emitted as soon a row is received and parsed
var row;
while (row = this.read()) {
console.log('time %s and value %s', row.time, row.val);
}
})
.on('end', function () {
// Stream ended, there aren't any more rows
})
.on('error', function (err) {
// Something went wrong: err is a response error from Cassandra
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1025 次 |
| 最近记录: |