Cassandra nodejs eachRow return 在数据库查询完成之前

Cassandra nodejs eachRow return before db query completed

我将 Cassandra 与 nodejs 一起使用,以通过 eachRow 获取大数据 table。

我需要在每一行中插入数据,但由于某种原因它没有等待查询,它在完成之前就完成了。

client.eachRow(query, [], { prepare: true, autoPage : true, fetchSize: 500 }, function(index, row) {
     // DB query / insert or update
, function(err, result) {
    // Finish all rows.
});

有什么建议吗?

只需浏览官方的 cassandra-driver 文档 https://www.npmjs.com/package/cassandra-driver 并找出这一行

The #stream() method works in the same way but instead of callback it returns a Readable Streams2 object in objectMode that emits instances of 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
  });