Run multiple queries sequentially

Hi !

I’m working with the nodejs couchbase SDK and I would like to run multiples N1QL queries sequentially like:

  • Run query A
  • Wait for response A
  • Run query B
  • Wait for response B

I’ve looked up on nodejs promises feature but I’m quite new to nodeJS and I’m not sure this is the right way to do it. I’ve seen https://www.npmjs.com/package/couchbase-promises but it seems their is no support for bucket.query() method with promises?

What is the simpliest way to achieve this?

Thank you for pointing me on the right direction as I’m a bit lost here!

Hey @martin.hogge,

Here is an example of running two queries simultaneously, let me know if you need any further help!

var cluster = new couchbase.Cluster('connection string');
var bucket = cluster.openBucket('default');
bucket.query(couchbase.N1qlQuery.fromString('...'), function(err, res) {
  console.log('query 1 complete', err, res);
});
bucket.query(couchbase.N1qlQuery.fromString('...'), function(err, res) {
  console.log('query 2 complete', err, res);
});

Cheers, Brett

Hi, thank’s for the answer but I don’t think this is really what I want. I would like to wait for the first query result before executing the 2nd query result, etc.

Maybe my SO post is clearer, you can check it here: https://stackoverflow.com/q/44255546/3520621

I resolved my issue thanks to https://stackoverflow.com/q/44255546/3520621.