Escape dot character ['.'] on path for mutateIn operations


#1

Hi, I need to insert a key-value pair on a doc on which the key string contains dots, the problem is that the insert method of the mutateIn builder interprets the key as the path and therefore, instead of creating a single key-value pair, it creates a tree.

Example, this code:

const key   = 'perfmon.phy_disk.pct_disk_read_time';
const value = 123;

bucket.mutateIn(docKey)
      .insert(key, value)
      .execute(err => {
        ...
      });

Creates this doc:

{
    perfmon: {
      phy_disk: {
        pct_disk_read_time: 123
      }
   }
}

What I want to obtain is instead:

{
    perfmon.phy_disk.pct_disk_read_time: 123
}

Is there a way to escape the dot char for the insert operation?

Thanks in advance,
Juan


#2

Yes there is - see https://developer.couchbase.com/documentation/server/5.5/sdk/subdocument-operations.html


#3

Thanks a lot Dave, this solved the problem. It would be very handy to have at least a link or reference to this documentation at the Node.js SDK page as it does’t mention it at all.

Thanks again!
Juan