Container class

Operations for reading, replacing, or deleting a specific, existing container by id.

See Containers for creating new containers, and reading/querying all containers; use .containers.

Note: all these operations make calls against a fixed budget. You should design your system such that these calls scale sublinearly with your application. For instance, do not call container(id).read() before every single item.read() call, to ensure the container exists; do this once on application start up.

Properties

conflicts

Operations for reading and querying conflicts for the given container.

For reading or deleting a specific conflict, use .conflict(id).

database
id
items

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

For reading, replacing, or deleting an existing item, use .item(id).

Example

Create a new item

const {body: createdItem} = await container.items.create({id: "<item id>", properties: {}});
scripts

All operations for Stored Procedures, Triggers, and User Defined Functions

url

Returns a reference URL to the resource. Used for linking in Permissions.

Methods

conflict(string, PartitionKey)

Used to read, replace, or delete a specific, existing Conflict by id.

Use .conflicts for creating new conflicts, or querying/reading all conflicts.

delete(RequestOptions)

Delete the container

deleteAllItemsForPartitionKey(PartitionKey, RequestOptions)

Delete all documents belong to the container for the provided partition key value

getFeedRanges()
getPartitionKeyDefinition()

Gets the partition key definition first by looking into the cache otherwise by reading the collection.

getQueryPlan(string | SqlQuerySpec)
item(string, PartitionKey)

Used to read, replace, or delete a specific, existing Item by id.

Use .items for creating new items, or querying/reading all items.

Example

Replace an item const {body: replacedItem} = await container.item("<item id>", "<partition key value>").replace({id: "<item id>", title: "Updated post", authorID: 5});

read(RequestOptions)

Read the container's definition

readOffer(RequestOptions)

Gets offer on container. If none exists, returns an OfferResponse with undefined.

readPartitionKeyRanges(FeedOptions)
replace(ContainerDefinition, RequestOptions)

Replace the container's definition

Property Details

conflicts

Operations for reading and querying conflicts for the given container.

For reading or deleting a specific conflict, use .conflict(id).

Conflicts conflicts

Property Value

database

database: Database

Property Value

id

id: string

Property Value

string

items

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

For reading, replacing, or deleting an existing item, use .item(id).

Example

Create a new item

const {body: createdItem} = await container.items.create({id: "<item id>", properties: {}});
Items items

Property Value

scripts

All operations for Stored Procedures, Triggers, and User Defined Functions

Scripts scripts

Property Value

url

Returns a reference URL to the resource. Used for linking in Permissions.

string url

Property Value

string

Method Details

conflict(string, PartitionKey)

Used to read, replace, or delete a specific, existing Conflict by id.

Use .conflicts for creating new conflicts, or querying/reading all conflicts.

function conflict(id: string, partitionKey?: PartitionKey): Conflict

Parameters

id

string

The id of the Conflict.

partitionKey
PartitionKey

Returns

delete(RequestOptions)

Delete the container

function delete(options?: RequestOptions): Promise<ContainerResponse>

Parameters

options
RequestOptions

Returns

deleteAllItemsForPartitionKey(PartitionKey, RequestOptions)

Delete all documents belong to the container for the provided partition key value

function deleteAllItemsForPartitionKey(partitionKey: PartitionKey, options?: RequestOptions): Promise<ContainerResponse>

Parameters

partitionKey
PartitionKey

The partition key value of the items to be deleted

options
RequestOptions

Returns

getFeedRanges()

function getFeedRanges(): Promise<readonly FeedRange[]>

Returns

Promise<readonly FeedRange[]>

all the feed ranges for which changefeed could be fetched.

getPartitionKeyDefinition()

Warning

This API is now deprecated.

This method has been renamed to readPartitionKeyDefinition.

Gets the partition key definition first by looking into the cache otherwise by reading the collection.

function getPartitionKeyDefinition(): Promise<ResourceResponse<PartitionKeyDefinition>>

Returns

getQueryPlan(string | SqlQuerySpec)

function getQueryPlan(query: string | SqlQuerySpec): Promise<Response_2<PartitionedQueryExecutionInfo>>

Parameters

query

string | SqlQuerySpec

Returns

Promise<Response_2<PartitionedQueryExecutionInfo>>

item(string, PartitionKey)

Used to read, replace, or delete a specific, existing Item by id.

Use .items for creating new items, or querying/reading all items.

Example

Replace an item const {body: replacedItem} = await container.item("<item id>", "<partition key value>").replace({id: "<item id>", title: "Updated post", authorID: 5});

function item(id: string, partitionKeyValue?: PartitionKey): Item

Parameters

id

string

The id of the Item.

partitionKeyValue
PartitionKey

The value of the Item partition key

Returns

read(RequestOptions)

Read the container's definition

function read(options?: RequestOptions): Promise<ContainerResponse>

Parameters

options
RequestOptions

Returns

readOffer(RequestOptions)

Gets offer on container. If none exists, returns an OfferResponse with undefined.

function readOffer(options?: RequestOptions): Promise<OfferResponse>

Parameters

options
RequestOptions

Returns

Promise<OfferResponse>

readPartitionKeyRanges(FeedOptions)

function readPartitionKeyRanges(feedOptions?: FeedOptions): QueryIterator<PartitionKeyRange>

Parameters

feedOptions
FeedOptions

Returns

QueryIterator<PartitionKeyRange>

replace(ContainerDefinition, RequestOptions)

Replace the container's definition

function replace(body: ContainerDefinition, options?: RequestOptions): Promise<ContainerResponse>

Parameters

options
RequestOptions

Returns