Collection.insertMany(documents)

Note:

The content in this help topic pertains to SuiteScript 2.1.

Method Description

Inserts multiple documents and generates an _id for each document.

Insertion results follow the input order. The combined normalized document bodies must not exceed 10 MB, excluding generated IDs. An empty array is accepted and inserts no documents.

Returns

Promise Object. Resolves to dataStore.InsertManyResult.

Supported Script Types

Server scripts

Governance

10 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

documents

Object[]

required

The array of documents to insert.

Each document can be an empty object. Don't include a top-level _id in any document.

For supported values and the stored document format, see dataStore.Document.

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

Property names must be nonempty. They can't contain dots, start with $, or use reserved property names.

An inserted document contains an unsupported property name, including within nested objects or arrays.

DATA_STORE_INVALID_DOCUMENT

The generated update path exceeds 4,000 bytes after UTF-8 encoding. Shorten the property name.

A property name produces an internal path that exceeds the 4,000-byte limit.

DATA_STORE_INVALID_DOCUMENT

Document numbers must be 0 or have an absolute value of at least 1e-130 and less than 1e126.

A nonzero number in a document has an absolute value below 1e-130 or greater than or equal to 1e126.

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

A document must be a non-null object.

An inserted document is null.

DATA_STORE_INVALID_DOCUMENT

Document IDs are generated automatically. Omit the top-level _id property when inserting documents.

The document includes a top-level _id.

DATA_STORE_INVALID_DOCUMENT

Document numbers must be finite, including numbers in nested objects and arrays.

A document contains a nonfinite number.

DATA_STORE_INVALID_DOCUMENT

Data Store inputs must not contain circular references.

A document, query, or update input contains a circular reference.

DATA_STORE_DOCUMENT_TOO_LARGE

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.

DATA_STORE_BATCH_TOO_LARGE

The combined JSON document bodies in this insert batch exceed 10 MB when encoded as UTF-8. Split the documents into smaller batches.

The combined normalized document bodies in an insert batch exceed 10 MB.

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_DUPLICATE_DOCUMENT

A document with the same identifier already exists.

Insertion encounters a duplicate generated document identifier 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.insertMany([
    { process: 'importA', status: 'pending', completed: 0 },
    { process: 'importB', status: 'pending', completed: 0 }
]);
const firstId = result.inserted[0].insertedId;

...
// Add additional code 

          

General Notices