N/dataStore Module
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
The following restrictions apply to this module:
-
Don't use the
N/dataStoremodule to store sensitive information. -
N/dataStoreisn'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:
-
Create a dataStore.Datastore object by calling dataStore.getDatastore(id).
-
Create a dataStore.Collection object by calling Datastore.getCollection(id) on the data store object.
-
Use the collection's methods to insert, retrieve, update, and delete documents. These methods return Promises. Use
awaitor the Promise object'sthen()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.
-
Account - Non-SuiteApp scripts share data.
-
SuiteApp - Scripts belonging to the same SuiteApp share data. It is separate from account-scope data and data belonging to other SuiteApps.
N/dataStore Objects and Members
N/dataStore Module Members
|
Member Type |
Name |
Return Type / Value Type |
Supported Script Types |
Description |
|---|---|---|---|---|
|
Object |
Object |
Server scripts |
Represents a collection of documents within a data store. Use its methods to insert, retrieve, update, and delete documents. |
|
|
Object |
Object |
Server scripts |
Iterates asynchronously over matching document results. Each result contains a document and its metadata. |
|
|
Object |
Object |
Server scripts |
Represents a data store. Use it to access collections within that data store. |
|
|
Object |
Object |
Server scripts |
Contains the number of documents deleted by |
|
|
Object |
Object |
Server scripts |
Represents a stored JSON document. Contains the generated |
|
|
Object |
Object |
Server scripts |
Contains information about the document: its size in bytes and its version. |
|
|
Object |
Object |
Server scripts |
Contains a matching document and its metadata. |
|
|
Object |
Object |
Server scripts |
Contains a matching document and its metadata, returned when iterating over a cursor. |
|
|
Object |
Object |
Server scripts |
Contains the number of documents inserted and the insertion result for each document. |
|
|
Object |
Object |
Server scripts |
Contains an inserted document's generated identifier and metadata. |
|
|
Object |
Object |
Server scripts |
Contains the number of documents updated. |
|
|
Method |
Server scripts |
Returns a dataStore.Collection object for the specified collection in the |
||
|
Method |
Server scripts |
Returns a dataStore.Datastore object for the specified data store in the executing script's storage scope. |