To Update Document Content
You can update a document without needing to provide metadata that you are not updating.
The Integration Department has completed their collection of Marketing, Sales, and Training employees to let go.
To keep track of where they are, they are changing the Attrition Department description:
"The Attrition Department contains redundant employees from Marketing, Sales, and Training."
To update this description, we merely provided the URI and the entire document with the new description replacing the original description:
declareUpdate(); const op = require("/MarkLogic/optic"); op.fromDocDescriptors([ { uri: "/data/departments/Attrition.json", doc: { "Department": "Attrition", "LineOfBusiness": "Cross-Department Collaboration", "Description": "The Attrition Department contains redundant employees from Marketing, Sales, and Training." } }]) .write() .result();
Here is the 1 row x 2 column result:
{ "doc": { "Department": "Attrition", "LineOfBusiness": "Cross-Department Collaboration", "Description": "The Attrition Department contains redundant employees from Marketing, Sales, and Training." }, "uri": "/data/departments/Attrition.json" }
write()
writes only the data from the columns that the data accessor provides. So, you do not need to providecollections
orpermissions
or any other metadata column unless you are also updating that data.Before executing this update, you can check that it will affect only the data you choose for only the documents you choose by commenting out
write()
. The resulting update returns the rows thatfromDocDescriptors()
accesses.