Collection.deleteOne(query)

Note:

The content in this help topic pertains to SuiteScript 2.1.

Method Description

Deletes the first document that matches the query.

Matching documents are ordered by _id in ascending order.

Returns

Promise Object. Resolves to dataStore.DeleteResult.

Supported Script Types

Server scripts

Governance

2 units

Module

N/dataStore Module

Parent Object

dataStore.Collection

Sibling Object Members

Collection Object Members

Since

2026.2

Parameters

Parameter

Type

Required / Optional

Description

Since

query

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

Errors

Error Code

Error Message

Thrown If

DATA_STORE_NOT_ENABLED

The N/dataStore API isn't enabled for this account.

Data Store is disabled for the account.

DATA_STORE_BUNDLE_NOT_SUPPORTED

The N/dataStore API isn't supported for scripts that belong to a bundle.

The executing script belongs to a bundle.

DATA_STORE_INVALID_DOCUMENT

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_INVALID_DOCUMENT

Data Store inputs must not contain circular references.

The query contains a circular reference.

DATA_STORE_INVALID_QUERY

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.

DATA_STORE_INVALID_QUERY

Use no more than 100 values with each $in operator.

An $in operand contains more than 100 values.

DATA_STORE_INVALID_QUERY

Use $and or $or for logical query operations.

A query uses an unsupported logical operator.

DATA_STORE_INVALID_QUERY

Field operator objects must contain at least one operator.

A field-operator object is empty.

DATA_STORE_INVALID_QUERY

Use a number or string with ordering comparison operators.

An ordering comparison uses an incompatible operand.

DATA_STORE_INVALID_QUERY

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.

DATA_STORE_INVALID_QUERY

$exists requires true or false.

The $exists operand is not a boolean.

DATA_STORE_INVALID_QUERY

Nested $elemMatch isn't supported.

The query nests $elemMatch.

DATA_STORE_INVALID_QUERY

Field paths are limited to 32 segments and 256 UTF-8 bytes.

A complete query path exceeds either limit.

DATA_STORE_INVALID_QUERY

Use nonempty object property names in field paths. Array indexes and JSONPath syntax aren't supported.

A field path contains unsupported syntax.

DATA_STORE_INVALID_QUERY

Query string literals are limited to 4,000 UTF-8 bytes.

A string operand exceeds the byte limit.

DATA_STORE_INVALID_QUERY

Query numbers must be finite.

A numeric query operand is nonfinite.

DATA_STORE_INVALID_QUERY

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 1e-130 or greater than or equal to 1e126.

DATA_STORE_INVALID_QUERY

Use JSON scalar values for comparisons. Objects and arrays can't be compared directly.

A direct comparison uses a nonscalar value.

DATA_STORE_INVALID_QUERY

A query predicate must be a JSON object.

A query predicate is not an object.

DATA_STORE_INVALID_QUERY

Query object keys must be strings.

A query object has a nonstring key.

DATA_STORE_INVALID_QUERY

Logical and membership operators require nonempty arrays.

A logical or membership operand is empty or is not an array.

DATA_STORE_TOO_MANY_PARAMETERS

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.

DATA_STORE_LOCK_TIMEOUT

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.

DATA_STORE_OUTCOME_UNKNOWN

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.

DATA_STORE_COMMITTED_RESULT_UNAVAILABLE

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

Important:

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.deleteOne({ _id: documentId });

...
// Add additional code 

          

General Notices