MarkLogic Server 11.0 Product Documentation
PatchBuilderPlan.prototype.insertNamedChild

PatchBuilderPlan.prototype.insertNamedChild(
   path as String,
   key as String,
   content as Node
) as PatchBuilderPlan

Summary

This method is specific for JSON and inserts a key/value pair to an object.

Parameters
path The path which returns an JSON Object.
key The key to insert.
content The new content.

Example

'use strict';
declareUpdate();
const op = require('/MarkLogic/optic');
const docDescriptors = [{uri: '/optic/update/write4.json', doc:xdmp.unquote("{key:{ key2: 2}}")},
                        {uri:  '/optic/update/write5.json',doc:xdmp.unquote("{key:{ key2: 2}}")}]
op.fromDocDescriptors(docDescriptors)
.patch(op.col('doc'),
       op.patchBuilder('/')
         .insertNamedChild("key","key3",3)
      )
.write()
.result();
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy