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)
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\', \'
\')' },
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.