dataStore.Collection

Note:

The content in this help topic pertains to SuiteScript 2.1.

Object Description

Represents a collection of documents within a data store. Use its methods to insert, retrieve, update, and delete documents.

This object is returned by dataStore.getCollection(id) and Datastore.getCollection(id).

To select documents for retrieval, updates, or deletion, construct a query object and pass it to the corresponding collection method. For supported query syntax, see Data Store Query Object. For update operators, rules, and limits, see Data Store Update Object.

Inserted documents must use supported property names. For the requirements, see Data Store Query Rules. When inserting, updating, or deleting documents, consider the following behavior:

  • Separate API calls. Each call saves its changes independently of the surrounding record or script transaction. Changes saved by one call aren't rolled back if a later call fails.

  • Multiple-document operations. Each insertMany, updateMany, or deleteMany call saves its selected changes together or rolls them back together. These methods don't return partial-success results.

  • Uncertain outcome. If an operation fails with DATA_STORE_OUTCOME_UNKNOWN, its changes may have been saved. Don't retry automatically. Check whether the intended changes were applied before deciding whether to retry.

  • Unavailable result. If an operation fails with DATA_STORE_COMMITTED_RESULT_UNAVAILABLE, its changes were saved, but the result couldn't be returned. Don't retry the operation.

Retrying an update that uses $inc could apply the increment twice.

Supported Script Types

Server scripts

Module

N/dataStore Module

Methods and Properties

Collection Object Members

Since

2026.2

Collection Object Members

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Method

Collection.deleteMany(query)

Promise Object

Server scripts

Deletes all documents that match the query.

Method

Collection.deleteOne(query)

Promise Object

Server scripts

Deletes the first document that matches the query.

Method

Collection.find(query)

Promise Object

Server scripts

Finds all documents that match the query.

Method

Collection.findOne(query)

Promise Object

Server scripts

Finds the first document that matches the query.

Method

Collection.insertMany(documents)

Promise Object

Server scripts

Inserts multiple documents and generates an _id for each document.

Method

Collection.insertOne(document)

Promise Object

Server scripts

Inserts one document and generates its _id.

Method

Collection.updateMany(query, update)

Promise Object

Server scripts

Updates all documents that match the query.

Method

Collection.updateOne(query, update)

Promise Object

Server scripts

Updates the first document that matches the query.

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 datastore = dataStore.getDatastore('processing');
const collection = datastore.getCollection('checkpoints');

...
// Add additional code 

          

General Notices