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

Can we please have a working paste-and-run Node 3.0 code sample?

    XMLWordPrintable

Details

    Description

      Something along the lines of this, with best practices, if possible (I'm not a Node expert, can't offer that):

      ======

      'use strict';
      var couchbase = require('couchbase');
      // Create a Couchbase Cluster connection
      var cluster = new couchbase.Cluster('couchbase://localhost',

      { username: 'Administrator', password: 'password' }

      );
      // Open a specific Couchbase bucket, `travel-sample` in this case.
      var bucket = cluster.bucket('travel-sample');
      // And select the default collection
      var collection = bucket.defaultCollection();
      // upsert document
      async function upsertDocument(key, value)

      { var result = await collection.upsert(key, value); }

      upsertDocument("my-document",

      {name: 'mike'}

      );
      // get document
      async function getDocument()
      {
      await collection.get('airline_10123', function(err, result)

      { if (err) throw err; console.log(result); }

      );
      }
      getDocument();

      =======

      If someone tries to use our current example, they won't get far. It's pretty frustrating.

      Reporter: Oleg Kuzmin
      E-mail: oleg.kuzmin@couchbase.com

      Attachments

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

        Activity

          Hi Oleg,

          I hope that the reworked example in https://docs.couchbase.com/nodejs-sdk/3.0/hello-world/start-using-sdk.html does the trick.

          richard.smedley Richard Smedley added a comment - Hi Oleg, I hope that the reworked example in  https://docs.couchbase.com/nodejs-sdk/3.0/hello-world/start-using-sdk.html  does the trick.

          Thank you, Richard - it definitely looks much better, I went through all the steps, and it worked for me.  Just one thing that I would add at the very beginning of that page - the Node.js version compatibility for our Node.js SDK 3.0.  It helps to know that you should have Node 10.x or 12.x before you proceed with the rest of the steps.

          oleg.kuzmin Oleg Kuzmin (Inactive) added a comment - Thank you, Richard - it definitely looks much better, I went through all the steps, and it worked for me.  Just one thing that I would add at the very beginning of that page - the Node.js version compatibility for our Node.js SDK 3.0.  It helps to know that you should have Node 10.x or 12.x before you proceed with the rest of the steps.

          Good idea - it was on the compat page, but v useful to add it here (and to the release notes page), which I've just done - https://github.com/couchbase/docs-sdk-nodejs/blob/release/3.0/modules/hello-world/pages/start-using-sdk.adoc

          ... will be in the next docs build.

          richard.smedley Richard Smedley added a comment - Good idea - it was on the compat page, but v useful to add it here (and to the release notes page), which I've just done -  https://github.com/couchbase/docs-sdk-nodejs/blob/release/3.0/modules/hello-world/pages/start-using-sdk.adoc ... will be in the next docs build.

          People

            richard.smedley Richard Smedley
            oleg.kuzmin Oleg Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty