Items class

Operations for creating new items, and reading/querying all items

Properties

container

Methods

batch(OperationInput[], string, RequestOptions)

Execute transactional batch operations on items. Batch takes an array of Operations which are typed based on what the operation does. Batch is transactional and will rollback all operations if one fails. The choices are: Create, Upsert, Read, Replace, and Delete

Usage example:

// partitionKey is required as a second argument to batch, but defaults to the default partition key
const operations: OperationInput[] = [
   {
      operationType: "Create",
      resourceBody: { id: "doc1", name: "sample", key: "A" }
   },
   {
      operationType: "Upsert",
      partitionKey: 'A',
      resourceBody: { id: "doc2", name: "other", key: "A" }
   }
]

await database.container.items.batch(operations)
bulk(OperationInput[], BulkOptions, RequestOptions)

Execute bulk operations on items. Bulk takes an array of Operations which are typed based on what the operation does. The choices are: Create, Upsert, Read, Replace, and Delete

Usage example:

// partitionKey is optional at the top level if present in the resourceBody
const operations: OperationInput[] = [
   {
      operationType: "Create",
      resourceBody: { id: "doc1", name: "sample", key: "A" }
   },
   {
      operationType: "Upsert",
      partitionKey: 'A',
      resourceBody: { id: "doc2", name: "other", key: "A" }
   }
]

await database.container.items.bulk(operations)
changeFeed(ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

changeFeed(string | number | boolean, ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

changeFeed<T>(ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

changeFeed<T>(string | number | boolean, ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

create<T>(T, RequestOptions)

Create an item. Any provided type, T, is not necessarily enforced by the SDK. You may get more or less properties and it's up to your logic to enforce it.

There is no set schema for JSON items. They may contain any number of custom properties.

query(string | SqlQuerySpec, FeedOptions)

Queries all items.

query<T>(string | SqlQuerySpec, FeedOptions)

Queries all items.

readAll(FeedOptions)

Read all items. There is no set schema for JSON items. They may contain any number of custom properties.

readAll<T>(FeedOptions)

Read all items. Any provided type, T, is not necessarily enforced by the SDK. You may get more or less properties and it's up to your logic to enforce it.

There is no set schema for JSON items. They may contain any number of custom properties.

readChangeFeed(ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

readChangeFeed(string | number | boolean, ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

readChangeFeed<T>(ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

readChangeFeed<T>(string | number | boolean, ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

upsert(unknown, RequestOptions)

Upsert an item. There is no set schema for JSON items. They may contain any number of custom properties.

upsert<T>(T, RequestOptions)

Upsert an item. Any provided type, T, is not necessarily enforced by the SDK. You may get more or less properties and it's up to your logic to enforce it.

There is no set schema for JSON items. They may contain any number of custom properties.

Property Details

container

container: Container

Property Value

Method Details

batch(OperationInput[], string, RequestOptions)

Execute transactional batch operations on items. Batch takes an array of Operations which are typed based on what the operation does. Batch is transactional and will rollback all operations if one fails. The choices are: Create, Upsert, Read, Replace, and Delete

Usage example:

// partitionKey is required as a second argument to batch, but defaults to the default partition key
const operations: OperationInput[] = [
   {
      operationType: "Create",
      resourceBody: { id: "doc1", name: "sample", key: "A" }
   },
   {
      operationType: "Upsert",
      partitionKey: 'A',
      resourceBody: { id: "doc2", name: "other", key: "A" }
   }
]

await database.container.items.batch(operations)
function batch(operations: OperationInput[], partitionKey?: string, options?: RequestOptions)

Parameters

operations

OperationInput[]

List of operations. Limit 100

partitionKey

string

options
RequestOptions

Used for modifying the request

Returns

Promise<Response<any>>

bulk(OperationInput[], BulkOptions, RequestOptions)

Execute bulk operations on items. Bulk takes an array of Operations which are typed based on what the operation does. The choices are: Create, Upsert, Read, Replace, and Delete

Usage example:

// partitionKey is optional at the top level if present in the resourceBody
const operations: OperationInput[] = [
   {
      operationType: "Create",
      resourceBody: { id: "doc1", name: "sample", key: "A" }
   },
   {
      operationType: "Upsert",
      partitionKey: 'A',
      resourceBody: { id: "doc2", name: "other", key: "A" }
   }
]

await database.container.items.bulk(operations)
function bulk(operations: OperationInput[], bulkOptions?: BulkOptions, options?: RequestOptions)

Parameters

operations

OperationInput[]

List of operations. Limit 100

bulkOptions
BulkOptions

Optional options object to modify bulk behavior. Pass { continueOnError: true } to continue executing operations when one fails. (Defaults to false) ** NOTE: THIS WILL DEFAULT TO TRUE IN THE 4.0 RELEASE

options
RequestOptions

Used for modifying the request.

Returns

Promise<OperationResponse[]>

changeFeed(ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

function changeFeed(changeFeedOptions?: ChangeFeedOptions)

Parameters

changeFeedOptions
ChangeFeedOptions

Returns

changeFeed(string | number | boolean, ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

function changeFeed(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions)

Parameters

partitionKey

string | number | boolean

changeFeedOptions
ChangeFeedOptions

Returns

changeFeed<T>(ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

function changeFeed<T>(changeFeedOptions?: ChangeFeedOptions)

Parameters

changeFeedOptions
ChangeFeedOptions

Returns

changeFeed<T>(string | number | boolean, ChangeFeedOptions)

Create a ChangeFeedIterator to iterate over pages of changes

function changeFeed<T>(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions)

Parameters

partitionKey

string | number | boolean

changeFeedOptions
ChangeFeedOptions

Returns

create<T>(T, RequestOptions)

Create an item. Any provided type, T, is not necessarily enforced by the SDK. You may get more or less properties and it's up to your logic to enforce it.

There is no set schema for JSON items. They may contain any number of custom properties.

function create<T>(body: T, options?: RequestOptions)

Parameters

body

T

Represents the body of the item. Can contain any number of user defined properties.

options
RequestOptions

Used for modifying the request (for instance, specifying the partition key).

Returns

Promise<ItemResponse<T>>

query(string | SqlQuerySpec, FeedOptions)

Queries all items.

function query(query: string | SqlQuerySpec, options?: FeedOptions)

Parameters

query

string | SqlQuerySpec

Query configuration for the operation. See <xref:SqlQuerySpec> for more info on how to configure a query.

options
FeedOptions

Used for modifying the request (for instance, specifying the partition key).

Returns

query<T>(string | SqlQuerySpec, FeedOptions)

Queries all items.

function query<T>(query: string | SqlQuerySpec, options?: FeedOptions)

Parameters

query

string | SqlQuerySpec

Query configuration for the operation. See <xref:SqlQuerySpec> for more info on how to configure a query.

options
FeedOptions

Used for modifying the request (for instance, specifying the partition key).

Returns

readAll(FeedOptions)

Read all items. There is no set schema for JSON items. They may contain any number of custom properties.

function readAll(options?: FeedOptions)

Parameters

options
FeedOptions

Used for modifying the request (for instance, specifying the partition key).

Returns

readAll<T>(FeedOptions)

Read all items. Any provided type, T, is not necessarily enforced by the SDK. You may get more or less properties and it's up to your logic to enforce it.

There is no set schema for JSON items. They may contain any number of custom properties.

function readAll<T>(options?: FeedOptions)

Parameters

options
FeedOptions

Used for modifying the request (for instance, specifying the partition key).

Returns

readChangeFeed(ChangeFeedOptions)

Warning

This API is now deprecated.

Use changeFeed instead.

Create a ChangeFeedIterator to iterate over pages of changes

function readChangeFeed(changeFeedOptions?: ChangeFeedOptions)

Parameters

changeFeedOptions
ChangeFeedOptions

Returns

readChangeFeed(string | number | boolean, ChangeFeedOptions)

Warning

This API is now deprecated.

Use changeFeed instead.

Create a ChangeFeedIterator to iterate over pages of changes

function readChangeFeed(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions)

Parameters

partitionKey

string | number | boolean

changeFeedOptions
ChangeFeedOptions

Returns

readChangeFeed<T>(ChangeFeedOptions)

Warning

This API is now deprecated.

Use changeFeed instead.

Create a ChangeFeedIterator to iterate over pages of changes

function readChangeFeed<T>(changeFeedOptions?: ChangeFeedOptions)

Parameters

changeFeedOptions
ChangeFeedOptions

Returns

readChangeFeed<T>(string | number | boolean, ChangeFeedOptions)

Warning

This API is now deprecated.

Use changeFeed instead.

Create a ChangeFeedIterator to iterate over pages of changes

function readChangeFeed<T>(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions)

Parameters

partitionKey

string | number | boolean

changeFeedOptions
ChangeFeedOptions

Returns

upsert(unknown, RequestOptions)

Upsert an item. There is no set schema for JSON items. They may contain any number of custom properties.

function upsert(body: unknown, options?: RequestOptions)

Parameters

body

unknown

Represents the body of the item. Can contain any number of user defined properties.

options
RequestOptions

Used for modifying the request (for instance, specifying the partition key).

Returns

upsert<T>(T, RequestOptions)

Upsert an item. Any provided type, T, is not necessarily enforced by the SDK. You may get more or less properties and it's up to your logic to enforce it.

There is no set schema for JSON items. They may contain any number of custom properties.

function upsert<T>(body: T, options?: RequestOptions)

Parameters

body

T

Represents the body of the item. Can contain any number of user defined properties.

options
RequestOptions

Used for modifying the request (for instance, specifying the partition key).

Returns

Promise<ItemResponse<T>>