Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-6230

How do stream over a large dataset? I only found the cluster.query() which returns promise

    XMLWordPrintable

Details

    Description

      I have been looking for a way to stream over the data using the emitter that is emitted by the QueryExecuter class (https://github.com/couchbase/couchnode/blob/3d0b7e8ef249ac2c912845320e5742b6fa6ff197/lib/queryexecutor.js#L9)
      but reading the docs, I could not find that method to use this class. On going through the Cluster class
      (https://github.com/couchbase/couchnode/blob/3d0b7e8ef249ac2c912845320e5742b6fa6ff197/lib/cluster.js#L228)
      I realized that the method mentioned here, cluster.query(), is a wrapper that is using the emitter internally and giving the complete dataset.

      I want to get the functionality mentioned in the code snippet in the docs. Also, I believe this snippet is misleading since the result receives a promise since the cluster.query is an async function and I get error result.on is not available
      var result = cluster.query(
      'SELECT x.* FROM `default` WHERE x.Type="User"');
      result.on('row', (row) =>

      { // handle the row var name = row.name; }

      );

      Reporter: Divyanshu Bhatnagar
      E-mail: bhatnagardivyanshu@gmail.com

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          I see that the documentation about streaming query results got removed - I have the same problem though.

          How is it possible to do this with the 3.0 SDK? Did the feature get removed?

          fsta Felix Stadthaus added a comment - I see that the documentation about streaming query results got removed - I have the same problem though. How is it possible to do this with the 3.0 SDK? Did the feature get removed?
          richard.smedley Richard Smedley added a comment - - edited The page has been updated with `queryResults()` https://docs.couchbase.com/nodejs-sdk/current/howtos/n1ql-queries-with-sdk.html#handling-results
          arun.vijayraghavan Arun Vijayraghavan added a comment - - edited

          I believe the feature thats being asked for goes something like this ?

           

              var couchbase = require('couchbase')

              var cluster = new couchbase.Cluster('couchbase://localhost/');

               cluster.authenticate('Administrator', 'password'); v

               var bucket = cluster.openBucket('travel-sample');

               var N1qlQuery = couchbase.N1qlQuery;

               var q = N1qlQuery.fromString('SELECT * FROM `travel-sample` LIMIT 100');

               var req = bucket.query(q);

                req.on('row', function(row

               

          {              console.log('Got a row');        }

            );

               req.on('error', function(err) {console.error('Got error %j', err);});

               req.on('end', function(meta){console.log('All rows received. Metadata is %j:', meta);});

          arun.vijayraghavan Arun Vijayraghavan added a comment - - edited I believe the feature thats being asked for goes something like this ?       var couchbase = require('couchbase')     var cluster = new couchbase.Cluster('couchbase://localhost/');      cluster.authenticate('Administrator', 'password'); v      var bucket = cluster.openBucket('travel-sample');      var N1qlQuery = couchbase.N1qlQuery;      var q = N1qlQuery.fromString('SELECT * FROM `travel-sample` LIMIT 100');      var req = bucket.query(q);       req.on('row', function(row       {              console.log('Got a row');        }   );      req.on('error', function(err) {console.error('Got error %j', err);});      req.on('end', function(meta){console.log('All rows received. Metadata is %j:', meta);});

          People

            richard.smedley Richard Smedley
            docsite-collector Docs Site Collector
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty