Data Store Update Object
An update object is a JavaScript object that specifies changes to top-level properties in stored documents. Use it with a query object that identifies the documents to update. For more information, see Data Store Query Object.
Pass an update object as the second argument to the following methods:
Update objects use update operator names as properties. Assign each operator an object containing the document properties to change and their values. For more information about how to construct an update object, see the following topics:
Syntax
The following example combines all three update operators in one update object.
The query selects a document by its _id. The update object makes the following changes:
-
Sets
statusto'running'. -
Removes
temporary. -
Adds
1to the existing value ofcompleted.
The document's completed property must already contain a number.
The following code sample shows how to define and use an update object. It isn't a functional example. For a complete script example, see N/dataStore Module Script Samples.
const result = await collection.updateOne(
{ _id: documentId },
{
$set: { status: 'running' },
$unset: { temporary: true },
$inc: { completed: 1 }
}
);