在数据库查询完成之前,Cassandra nodejs eachRow返回

我使用Cassandra与nodejs来获取eachRow大表。

我需要在每一行插入数据,但由于某种原因,它不会等待查询,并在完成之前完成。

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

有什么build议么?

只需通过官方cassandra驱动程序文档https://www.npmjs.com/package/cassandra-driver并找出这一行

#stream()方法以相同的方式工作,但不是callback而是在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 });