Uploaded image for project: 'Couchbase node.js Client Library'
  1. Couchbase node.js Client Library
  2. JSCBC-309

Escape characters forced into N1QL query text persisting into inserted document

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • Major
    • None
    • 2.1.7
    • None
    • None
    • Node 4.4.5, Express 4.14.0, Couchbase Node.js SDK 2.1.7, Couchbase 4.5.0-2203.

    Description

      I'm writing a training exercise illustrating using Javascript template literals (supported by Node 4.x+) to build a N1QL query. I have the following Express route:

      router.post("/customer", jsonParser, function(req, res) {

      var docId = "an-example-key";
      var doc = JSON.stringify(req.body);

      queryText = `UPSERT INTO ${bucketName} (KEY, VALUE) VALUES ('${docId}', '${doc}')`;
      query = n1qlQuery.fromString(queryText);

      var bucket = cluster.openBucket(bucketName, function(err){

      bucket.query(query, function(err, result){
      if(err)

      { res.json(err); }

      else

      { res.json(result); }

      });
      });

      });

      The SDK automatically escapes the tick-mark characters in my query text with back slashes, so the resulting query object appears as this, when printed:

      N1qlStringQuery {
      options: { statement: 'UPSERT INTO customer360 (KEY, VALUE) VALUES (\'an-example-key\', \'

      {"name":"Bratislavonia","type":"country"}

      \')' },
      isAdhoc: true }

      These back slashes persist into the final document, as shown in the image. Is the SDK intended to modify documents in this manner?

      Is there perhaps a flag to suppress this escaping behavior, when manually assembling query text as described? I've searched but not found anything on this in the public documentation, or another Node.js SDK issue. Apologies in advance if there's documentation on this, or another open issue, I haven't found yet.

      Attachments

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

        Activity

          People

            brett19 Brett Lawson
            leo.schuman Leo Schuman [X] (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