我使用带有nodejs的Cassandra来获取eachRow的大表。
我需要在每一行上插入数据,但出于某种原因,它不会等待查询,而是在完成之前完成。
client.eachRow(query, [], { prepare: true, autoPage : true, fetchSize: 500 }, function(index, row) {
// DB query / insert or update
, function(err, result) {
// Finish all rows.
});
有什么建议吗?
答案 0 :(得分:4)
只需通过官方cassandra-driver doc 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
});