SODA for In-Database JavaScript Read and Write Operations

The primary way you specify read and write operations (other than insert and save) is to use methods provided by the SodaOperation class. You can chain together SodaOperation methods to specify read or write operations against a collection.

Nonterminal SodaOperation methods return the same object on which they are invoked, allowing them to be chained together.

A terminal SodaOperation method always appears at the end of a method chain to execute the operation.

Note:

A SodaOperation object is an internal object. You should not directly modify its properties.

Unless the SODA documentation for a method says otherwise, you can chain together any nonterminal methods and you can end the chain with any terminal method. However, not all combinations make sense. For example, it does not make sense to chain method version() together with a method that does not uniquely identify the document, such as keys().

Table 8-1 Overview of Nonterminal Methods for Read Operations

Method Description
key() Find a document that has the specified document key.
keys() Find documents that have the specified document keys.
filter() Find documents that match a filter specification (a query-by-example expressed in JSON).
version() Find documents that have the specified version. This is typically used with key().
headerOnly() Exclude document content from the result.
skip() Skip the specified number of documents in the result.
limit() Limit the number of documents in the result to the specified number.

Table 8-2 Overview of Terminal Methods for Read Operations

Method Description
getOne() Create and execute an operation that returns at most one document. For example, an operation that includes an invocation of nonterminal method key().
getCursor() Get a cursor over read operation results.
count() Count the number of documents found by the operation.
getDocuments() Gets an array of documents matching the query criteria.

Table 8-3 Overview of Terminal Methods for Write Operations

Method Description
replaceOne() Replace one document.
replaceOneAndGet() Replace one document and return the result document.
remove() Remove documents from a collection.

See Also: