简体   繁体   中英

return from eachRow() cassandra-driver for nodejs

In my node application, i am using following code to run some query. I want to call callback function after (arraySize > 100) and exit. Currently i can only exit after all processing is complete.

var matchedUsers = [];
client.eachRow(query, [], { prepare : true }, function (n, row) { 
      if(someCondition){
        matchedUsers.push(row.x);
      }

      if(matchedUsers.length>100){
        //exit here
      }
     }, function (err) {
        callback(matchedUsers)
     } );

Here is the underlying implementation of eachRow:

If I am reading through their node.js driver correctly, the whole cassandra result is returned back to you based on the query your provide. So you might as well just add all of the results to your own data structure, and then just iterate through it to look for your match(and of course just break out of your loop when match is found).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM