N/dataStore Module

Note:

The content in this help topic pertains to SuiteScript 2.1.

The N/dataStore module stores internal application data as JSON objects, called documents, without requiring custom records. You can also use the module to retrieve, update, and delete these documents. Each document is stored in a collection within a data store.

N/dataStore Module Script Samples

Important:

The following restrictions apply to this module:

  • Don't use the N/dataStore module to store sensitive information.

  • N/dataStore isn't supported in scripts installed through SuiteBundler. A script deployed through SDF can fail if it is later installed as part of a bundle. To migrate scripts between accounts, use an Account Customization Projects or Copy to Account.

To work with stored data:

  1. Create a dataStore.Datastore object by calling dataStore.getDatastore(id).

  2. Create a dataStore.Collection object by calling Datastore.getCollection(id) on the data store object.

  3. Use the collection's methods to insert, retrieve, update, and delete documents. These methods return Promises. Use await or the Promise object's then() method to process their results. For details, see dataStore.Collection.

To use the default data store, call dataStore.getCollection(id) directly. You don't need to create a dataStore.Datastore object first. The default data store has the identifier default. Calling this method is equivalent to calling dataStore.getDatastore('default').getCollection(id).

The executing script determines which storage scope the API uses. Scripts in the same scope can access the same data stores and collections by using the same identifiers.

N/dataStore Objects and Members

N/dataStore Module Members

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Object

dataStore.Collection

Object

Server scripts

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

Object

dataStore.Cursor

Object

Server scripts

Iterates asynchronously over matching document results. Each result contains a document and its metadata.

Object

dataStore.Datastore

Object

Server scripts

Represents a data store. Use it to access collections within that data store.

Object

dataStore.DeleteResult

Object

Server scripts

Contains the number of documents deleted by Collection.deleteOne(query) or Collection.deleteMany(query).

Object

dataStore.Document

Object

Server scripts

Represents a stored JSON document. Contains the generated _id and the properties stored by your script.

Object

dataStore.DocumentMetadata

Object

Server scripts

Contains information about the document: its size in bytes and its version.

Object

dataStore.FindOneResult

Object

Server scripts

Contains a matching document and its metadata.

Object

dataStore.FindResult

Object

Server scripts

Contains a matching document and its metadata, returned when iterating over a cursor.

Object

dataStore.InsertManyResult

Object

Server scripts

Contains the number of documents inserted and the insertion result for each document.

Object

dataStore.InsertOneResult

Object

Server scripts

Contains an inserted document's generated identifier and metadata.

Object

dataStore.UpdateResult

Object

Server scripts

Contains the number of documents updated.

Method

dataStore.getCollection(id)

dataStore.Collection

Server scripts

Returns a dataStore.Collection object for the specified collection in the default data store.

Method

dataStore.getDatastore(id)

dataStore.Datastore

Server scripts

Returns a dataStore.Datastore object for the specified data store in the executing script's storage scope.

General Notices