Reference Source
import JSONStoreCollection from 'react-native-ibm-mobilefirst-jsonstore'
public class | source

JSONStoreCollection

This class represents a single JSONStore collection. Operations on the collection can be done by using the API for this class.

Static Member Summary

Static Public Members
public static get
public static get
public static get
public static get

Constructor Summary

Public Constructor
public

Method Summary

Public Methods
public

async addData(data: JSON, options: JSONStoreAddOptions): Promise<string, JSON>

Add data and create a new document in the collection.

public

async changeData(dataList: Array, jsonStoreChangeOptions: JSONStoreChangeOptions): Promise<number, JSON>

Change a list of documents in the collection.

public

Removes all documents from a collection, but does not destroy the collection.

public

Count the number of dirty documents in the collection.

public

Count the number of documents in the collection.

public

async countDocuments(query: Array<JSONStoreQueryPart>, includeDeleted: boolean): Promise<number, JSON>

Count the number of documents in the collection that are based on the given query.

public

Find all the dirty documents in the collection.

public

Find all documents in the collection.

public

Find a document in the collection based on the given ID.

public

Find documents in the collection that are based on the given query.

public

Find all documents in the collection that have the given ids.

public

Get a map of the additional search fields for this collection.

public

Get a map of all search fields for this collection.

public

Determines if the collection contains the given additional search field.

public

async hasSearchField(searchField: string): Promise<boolean, JSON>

The name of the search field to check for existence.

public

Determine if a document is dirty or not.

public

async markDocumentClean(document: JSON): Promise<number, JSON>

Mark a document in the collection clean.

public

async markDocumentsClean(documents: Array): Promise<number, JSON>

Mark an array of documents in the collection clean.

public

Permanently deletes all the documents that are stored in a collection and destroys the collection.

public

async removeDocumentById(id: number, markDirty: boolean): Promise<number, JSON>

Remove a document from the collection that is based on the given id.

public

async removeDocumentsById(ids: number, markDirty: boolean): Promise<number, JSON>

Remove array of documents from the collection, based on the given ids.

public

async replaceDocument(document: JSON, markDirty: boolean): Promise<number, JSON>

Replace a document in the collection.

public

async replaceDocuments(documents: Array, markDirty: boolean): Promise<number, JSON>

Replace an array of documents in the collection.

public

setAdditionalSearchField(key: string, searchFieldType: string): *

Set an additional search field for the collection.

public

setSearchField(key: string, searchFieldType: string): *

Set a search field for the collection.

public

sync()

Sync this collection based on Sync policy set when the collection was opened.

public

Determine if the collection was reopened when it was initialized.

Static Public Members

public static get BOOLEAN: string source

public static get INTEGER: string source

public static get NUMBER: string source

public static get STRING: string source

Public Constructors

public constructor(name: string) source

Params:

NameTypeAttributeDescription
name string

the name of the JSONStoreCollection.

Public Methods

public async addData(data: JSON, options: JSONStoreAddOptions): Promise<string, JSON> source

Add data and create a new document in the collection.

Params:

NameTypeAttributeDescription
data JSON

New JSON data to be added to the collection

options JSONStoreAddOptions
  • optional

Options to be applied while adding the object

Return:

Promise<string, JSON>

This function returns an empty string in case of success and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async changeData(dataList: Array, jsonStoreChangeOptions: JSONStoreChangeOptions): Promise<number, JSON> source

Change a list of documents in the collection.

Params:

NameTypeAttributeDescription
dataList Array

List of JSON documents

jsonStoreChangeOptions JSONStoreChangeOptions
  • optional

Options to be applied while changing the objects

Return:

Promise<number, JSON>

This function returns a number indicative of number of documents affected and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async clearCollection(): Promise<string, JSON> source

Removes all documents from a collection, but does not destroy the collection.

Return:

Promise<string, JSON>

This function returns an empty string in case of success. In case of any error this function returns a JSON.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async countAllDirtyDocuments(): Promise<number, JSON> source

Count the number of dirty documents in the collection.

Return:

Promise<number, JSON>

This function returns a number indicative of the count of all dirty documents. In case of any error this function returns a JSON.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async countAllDocuments(): Promise<number, JSON> source

Count the number of documents in the collection.

Return:

Promise<number, JSON>

This function returns a number indicative of the count of all documents. In case of any error this function returns a JSON.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async countDocuments(query: Array<JSONStoreQueryPart>, includeDeleted: boolean): Promise<number, JSON> source

Count the number of documents in the collection that are based on the given query.

Params:

NameTypeAttributeDescription
query Array<JSONStoreQueryPart>

An array of JSONStoreQueryPart objects that limits the count scope. Every query part in the arrayare joined by an OR operation.

includeDeleted boolean
  • optional

Additional options to modify the count operation.

Return:

Promise<number, JSON>

This function returns a number indicative of the count of documents based on given query and whether to include deleted documents. In case of any error this function returns a JSON.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async findAllDirtyDocuments(): Promise<Array, JSON> source

Find all the dirty documents in the collection.

Return:

Promise<Array, JSON>

This function returns an array of documents that are found dirty in the collection. In case of any error this function returns a JSON.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async findAllDocuments(options: JSONStoreFindOptions): Promise<Array, JSON> source

Find all documents in the collection.

Params:

NameTypeAttributeDescription
options JSONStoreFindOptions
  • optional

The find query that restricts the search.

Return:

Promise<Array, JSON>

This function returns an array of documents that are found in the collection with the given Find Options. In case of any error this function returns a JSON.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async findDocumentById(id: number): Promise<object, JSON> source

Find a document in the collection based on the given ID.

Params:

NameTypeAttributeDescription
id number

The unique id that is associated with a document in the database (the _id search field).

Return:

Promise<object, JSON>

This function returns a document that is found for this given id. In case of any error this function returns a JSON.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async findDocuments(query: Array<JSONStoreQueryPart>, options: JSONStoreFindOptions): Promise<Array, JSON> source

Find documents in the collection that are based on the given query.

Params:

NameTypeAttributeDescription
query Array<JSONStoreQueryPart>

An array of JSONStoreQueryPart objects that limits the count scope. Every query part in the arrayare joined by an OR operation.

options JSONStoreFindOptions
  • optional

Additional options to modify the count operation.

Return:

Promise<Array, JSON>

This function returns an array of all the documents that are found for this given query and find options. In case of any error this function returns a JSON.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async findDocumentsById(ids: Array): Promise<Array, JSON> source

Find all documents in the collection that have the given ids.

Params:

NameTypeAttributeDescription
ids Array

An array of unique ids that are associated with a document in the database (the _id search field).

Return:

Promise<Array, JSON>

This function returns an array of all the documents that are found for this given ids. In case of any error this function returns a JSON.

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async getAdditionalSearchFields(): Promise<object> source

Get a map of the additional search fields for this collection.

Return:

Promise<object>

This function returns an object of all the additional search fields for the given collection.

public async getSearchFields(): Promise<object> source

Get a map of all search fields for this collection.

Return:

Promise<object>

This function returns an object of all the search fields for the given collection.

public async hasAdditionalSearchField(searchField: string): Promise<boolean, JSON> source

Determines if the collection contains the given additional search field.

Params:

NameTypeAttributeDescription
searchField string

The name of the additional search field to check for existence.

Return:

Promise<boolean, JSON>

This function returns a boolean value indicative of whether the collection contains the given additional search field or not, and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async hasSearchField(searchField: string): Promise<boolean, JSON> source

The name of the search field to check for existence.

Params:

NameTypeAttributeDescription
searchField string

The name of the additional search field to check for existence.

Return:

Promise<boolean, JSON>

This function returns a boolean value indicative of whether the collection contains the given search field or not, and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async isDocumentDirty(id: number): Promise<boolean, JSON> source

Determine if a document is dirty or not.

Params:

NameTypeAttributeDescription
id number

ID of the document to be checked.

Return:

Promise<boolean, JSON>

This function returns a boolean value indicative of whether the document is dirty or not, and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async markDocumentClean(document: JSON): Promise<number, JSON> source

Mark a document in the collection clean.

Params:

NameTypeAttributeDescription
document JSON

JSON document to be marked as clean.

Return:

Promise<number, JSON>

This function returns a number indicative of number of documents affected and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async markDocumentsClean(documents: Array): Promise<number, JSON> source

Mark an array of documents in the collection clean.

Params:

NameTypeAttributeDescription
documents Array

An Array of JSON documents to be marked as clean.

Return:

Promise<number, JSON>

This function returns a number indicative of number of documents affected and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async removeCollection(): Promise<string, JSON> source

Permanently deletes all the documents that are stored in a collection and destroys the collection.

Return:

Promise<string, JSON>

This function returns an empty string in case of success and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async removeDocumentById(id: number, markDirty: boolean): Promise<number, JSON> source

Remove a document from the collection that is based on the given id.

Params:

NameTypeAttributeDescription
id number

ID of the document to be deleted.

markDirty boolean
  • optional

Mark the document as dirty. Default is false.

Return:

Promise<number, JSON>

This function returns a number indicative of number of documents affected and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async removeDocumentsById(ids: number, markDirty: boolean): Promise<number, JSON> source

Remove array of documents from the collection, based on the given ids.

Params:

NameTypeAttributeDescription
ids number

ID of the document to be deleted.

markDirty boolean
  • optional

Mark the document as dirty using this flag. Default is false.

Return:

Promise<number, JSON>

This function returns a number indicative of number of documents affected and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async replaceDocument(document: JSON, markDirty: boolean): Promise<number, JSON> source

Replace a document in the collection.

Params:

NameTypeAttributeDescription
document JSON

A JSONObject that represents the document to update in the collection. The document's '_id' is used to determine which document to replace.

markDirty boolean
  • optional

Mark the document as dirty using this flag. Default is false.

Return:

Promise<number, JSON>

This function returns a number indicative of number of documents affected and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public async replaceDocuments(documents: Array, markDirty: boolean): Promise<number, JSON> source

Replace an array of documents in the collection.

Params:

NameTypeAttributeDescription
documents Array

A List that contains JSONObjects that represent the documents to update in the collection. The document's '_id' is used to determine which document to replace. If all documents could not be updated, a rollback is performed to a state where no documents were updated.

markDirty boolean
  • optional

Mark the document as dirty using this flag. Default is false.

Return:

Promise<number, JSON>

This function returns a number indicative of number of documents affected and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}

public setAdditionalSearchField(key: string, searchFieldType: string): * source

Set an additional search field for the collection.

Params:

NameTypeAttributeDescription
key string

The name of the additional search field to add. Only useful before the collection is opened.

searchFieldType string

The type of the search field. Accepted values are ('boolean', 'integer', 'number', 'string')

Return:

*

public setSearchField(key: string, searchFieldType: string): * source

Set a search field for the collection.

Params:

NameTypeAttributeDescription
key string

The name of the additional search field to add. Only useful before the collection is opened.

searchFieldType string

The type of the search field. Accepted values are ('boolean', 'integer', 'number', 'string')

Return:

*

public sync() source

Sync this collection based on Sync policy set when the collection was opened.

public async wasReopened(): Promise<boolean, JSON> source

Determine if the collection was reopened when it was initialized.

Return:

Promise<boolean, JSON>

This function returns a boolean value and it returns a JSON in case of any error

Example:

- If the promise is rejected, an error JSON in the following format is available with more information.
{
     errorMsg: "Error adding data to collection: favourites", 
     reason: "Collection is not initialized."
}