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

NodeJS Query For Loop Example Shows Incorrect Syntax

    XMLWordPrintable

Details

    Description

      The example given in this page:

      var N1qlQuery = couchbase.N1qlQuery;
      // ...
      query = N1qlQuery.fromString('SELECT name, email FROM default LIMIT 10');
      bucket.query(query, function(err, rows, meta) {
      for (row in rows)

      { console.log('Name: %s. Email: %s', row.name, row.email); }

      });

      is not correct; when executed will return

      "undefined undefined"

      printed repeatedly by the "console.log" call for however many rows are returned in the result set.

      The correct syntax is:

      var N1qlQuery = couchbase.N1qlQuery;
      // ...
      query = N1qlQuery.fromString('SELECT name, email FROM default LIMIT 10');
      bucket.query(query, function(err, rows, meta) {
      for (row in rows)

      { console.log('Name: %s. Email: %s', rows[row].name, rows[row].email); }

      });

      Reporter: Morris Schreibman
      E-mail: mschreib_il@yahoo.com

      Attachments

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

        Activity

          docsite-collector Docs Site Collector created issue -
          mschreib_il Morris Schreibman added a comment - The code example is given at    https://developer.couchbase.com/documentation/server/current/sdk/nodejs/n1ql-queries-with-sdk.html    
          matt.carabine Matt Carabine made changes -
          Field Original Value New Value
          Reporter Docs Site Collector [ docsite-collector ] Morris Schreibman [ mschreib_il ]

          Brett Lawson, any ideas here? Looking at the code it should work, but clearly there might be some issue?

          matt.carabine Matt Carabine added a comment - Brett Lawson , any ideas here? Looking at the code it should work, but clearly there might be some issue?
          somesh.patel Somesh Patel [X] (Inactive) made changes -
          Workflow DOC Workflow [ 76185 ] Original DOC Workflow [ 98076 ]
          matt.carabine Matt Carabine made changes -
          Assignee Matt Carabine [ matt.carabine ] Amarantha Kulkarni [ amarantha.kulkarni ]
          amarantha.kulkarni Amarantha Kulkarni (Inactive) made changes -
          Component/s sdk [ 14110 ]
          amarantha.kulkarni Amarantha Kulkarni (Inactive) made changes -
          Fix Version/s to-be-triaged [ 16762 ]
          amarantha.kulkarni Amarantha Kulkarni (Inactive) made changes -
          Assignee Amarantha Kulkarni [ amarantha.kulkarni ] Richard Smedley [ richard smedley ]
          richard.smedley Richard Smedley made changes -
          Fix Version/s tech-debt [ 12416 ]
          Fix Version/s to-be-triaged [ 16762 ]
          richard.smedley Richard Smedley made changes -
          Labels collector-86389172 collector-86389172 node.js
          richard.smedley Richard Smedley made changes -
          Sprint DOC-2020-S17-Sep06 [ 1180 ]
          Priority Test Blocker [ 6 ]
          richard.smedley Richard Smedley made changes -
          Component/s server dev guide and SDKs [ 11814 ]
          Component/s sdk [ 14110 ]
          richard.smedley Richard Smedley made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          richard.smedley Richard Smedley made changes -
          Page URL https://docs.couchbase.com/nodejs-sdk/2.6/n1ql-queries-with-sdk.html
          Story Points 1
          Labels collector-86389172 node.js collector-86389172 node.js query
          richard.smedley Richard Smedley made changes -
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Resolved [ 5 ]

          People

            richard.smedley Richard Smedley
            mschreib_il Morris Schreibman
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty