Collection.updateOne(query, update)
The content in this help topic pertains to SuiteScript 2.1.
|
Method Description |
Updates the first document that matches the query. Matching documents are ordered by |
|
Returns |
Promise Object. Resolves to dataStore.UpdateResult. |
|
Supported Script Types |
Server scripts |
|
Governance |
2 units |
|
Module |
|
|
Parent Object |
|
|
Sibling Object Members |
|
|
Since |
2026.2 |
Parameters
|
Parameter |
Type |
Required / Optional |
Description |
Since |
|---|---|---|---|---|
|
|
Object |
required |
The conditions used to match documents in the collection. An empty object matches all documents. For the supported structure and operators, see Data Store Query Object. |
2026.2 |
|
|
Object |
required |
The changes to apply to matching documents. For supported structure and operators, see Data Store Update Object. |
2026.2 |
Errors
|
Error Code |
Error Message |
Thrown If |
|---|---|---|
|
|
The |
Data Store is disabled for the account. |
|
|
The |
The executing script belongs to a bundle. |
|
|
Functions can't be used as values in documents, queries, or updates. Replace each function with a supported value. |
A supplied document, query, or update contains a JavaScript function as a value, including within nested objects or arrays. |
|
|
Data Store inputs must not contain circular references. |
The query or update contains a circular reference. |
|
|
The query expression exceeds the limit of 300 operators. Simplify the query. |
The query expression contains more than 300 operators, including implicit comparisons and logical connectors. |
|
|
Use no more than 100 values with each |
An |
|
|
Use |
A query uses an unsupported logical operator. |
|
|
Field operator objects must contain at least one operator. |
A field-operator object is empty. |
|
|
Use a number or string with ordering comparison operators. |
An ordering comparison uses an incompatible operand. |
|
|
The field operator or direct object comparison isn't supported. Use a supported operator or compare individual object properties. |
A query uses an unsupported field operator or directly compares an object. |
|
|
|
The |
|
|
Nested |
The query nests |
|
|
Field paths are limited to 32 segments and 256 UTF-8 bytes. |
A complete query path exceeds either limit. |
|
|
Use nonempty object property names in field paths. Array indexes and JSONPath syntax aren't supported. |
A field path contains unsupported syntax. |
|
|
Query string literals are limited to 4,000 UTF-8 bytes. |
A string operand exceeds the byte limit. |
|
|
Query numbers must be finite. |
A numeric query operand is nonfinite. |
|
|
Query numbers must be 0 or have an absolute value of at least 1e-130 and less than 1e126. |
A nonzero numeric query value has an absolute value below |
|
|
Use JSON scalar values for comparisons. Objects and arrays can't be compared directly. |
A direct comparison uses a nonscalar value. |
|
|
A query predicate must be a JSON object. |
A query predicate is not an object. |
|
|
Query object keys must be strings. |
A query object has a nonstring key. |
|
|
Logical and membership operators require nonempty arrays. |
A logical or membership operand is empty or is not an array. |
|
|
The |
An update targets the immutable top-level ID. |
|
|
Use only one update operation per property. |
More than one update operation targets the same property. |
|
|
Use a finite number as the |
The increment operand is nonnumeric or nonfinite. |
|
|
Only |
An update uses an unsupported operator. |
|
|
The update and each operator operand must be JSON objects with at least one property. |
The update or an operator operand is not a nonempty object. |
|
|
Update object keys must be strings. |
An update object has a nonstring key. |
|
|
Property names must be nonempty. They can't contain dots, start with |
A target or nested update value uses an invalid property name. |
|
|
Numbers in update values must be finite. |
A numeric update value is nonfinite. |
|
|
The generated update path exceeds 4,000 bytes after UTF-8 encoding. Shorten the property name. |
An update property name produces a generated update path longer than 4,000 bytes after UTF-8 encoding. |
|
|
Use JSON-compatible values in updates. |
An update contains a value that is not JSON-compatible. |
|
|
|
A selected document has a missing or nonnumeric increment target. |
|
|
Update numbers must be 0 or have an absolute value of at least 1e-130 and less than 1e126. |
A nonzero number supplied in the update, including within nested objects or arrays, falls outside the supported range. |
|
|
The |
An out-of-range |
|
|
The JSON document body exceeds the 10 MB limit when encoded as UTF-8. Reduce the document size. |
An inserted or resulting updated document body exceeds 10 MB. |
|
|
The operation requires too many bound parameters. Simplify the query or reduce the batch size. |
The operation requires more than 32,000 bound parameters, including internal parameters. |
|
|
The operation timed out waiting for a document lock. Try again later. |
An update or deletion times out waiting for a document lock and rollback is confirmed. |
|
|
The operation may have been committed. Don't retry automatically. |
The operation's outcome can't be determined, and its changes may have been saved. |
|
|
The operation was committed, but its result couldn't be returned. Don't retry. |
The changes were saved, but the operation couldn't return its result. |
Syntax
The following code sample shows the syntax for this member. It isn't a functional example. For a complete script example, see N/dataStore Module Script Samples.
// Add additional code
...
const result = await collection.updateOne(
{ _id: documentId },
{ $set: { status: 'running' }, $inc: { completed: 1 } }
);
...
// Add additional code