CosmosClient class

Provides a client-side logical representation of the Azure Cosmos DB database account. This client is used to configure and execute requests in the Azure Cosmos DB database service.

Constructors

CosmosClient(CosmosClientOptions)

Creates a new <xref:CosmosClient> object. See <xref:CosmosClientOptions> for more details on what options you can use.

CosmosClient(string)

Creates a new <xref:CosmosClient> object from a connection string. Your database connection string can be found in the Azure Portal

Properties

databases

Used for creating new databases, or querying/reading all databases. Use .database(id) to read, replace, or delete a specific, existing database by id.

offers

Used for querying & reading all offers. Use .offer(id) to read, or replace existing offers.

Methods

database(string)

Used for reading, updating, or deleting a existing database by id or accessing containers belonging to that database. This does not make a network call. Use .read to get info about the database after getting the <xref:Database> object.

getDatabaseAccount(RequestOptions)

Get information about the current <xref:DatabaseAccount> (including which regions are supported, etc.)

getReadEndpoint()

Gets the currently used read endpoint. Useful for troubleshooting purposes. The url may contain a region suffix (e.g. "-eastus") if we're using location specific endpoints.

getWriteEndpoint()

Gets the currently used write endpoint url. Useful for troubleshooting purposes. The url may contain a region suffix (e.g. "-eastus") if we're using location specific endpoints.

offer(string)

Used for reading, or updating a existing offer by id.

Constructor Details

CosmosClient(CosmosClientOptions)

Creates a new <xref:CosmosClient> object. See <xref:CosmosClientOptions> for more details on what options you can use.

new CosmosClient(options: CosmosClientOptions)

Parameters

options
CosmosClientOptions

bag of options - require at least endpoint and auth to be configured

CosmosClient(string)

Creates a new <xref:CosmosClient> object from a connection string. Your database connection string can be found in the Azure Portal

new CosmosClient(connectionString: string)

Parameters

connectionString
string

Property Details

databases

Used for creating new databases, or querying/reading all databases. Use .database(id) to read, replace, or delete a specific, existing database by id.

databases: Databases

Property Value

offers

Used for querying & reading all offers. Use .offer(id) to read, or replace existing offers.

offers: Offers

Property Value

Method Details

database(string)

Used for reading, updating, or deleting a existing database by id or accessing containers belonging to that database. This does not make a network call. Use .read to get info about the database after getting the <xref:Database> object.

function database(id: string)

Parameters

id
string

The id of the database.

Returns

getDatabaseAccount(RequestOptions)

Get information about the current <xref:DatabaseAccount> (including which regions are supported, etc.)

function getDatabaseAccount(options?: RequestOptions)

Parameters

options
RequestOptions

Returns

getReadEndpoint()

Gets the currently used read endpoint. Useful for troubleshooting purposes. The url may contain a region suffix (e.g. "-eastus") if we're using location specific endpoints.

function getReadEndpoint()

Returns

Promise<string>

getWriteEndpoint()

Gets the currently used write endpoint url. Useful for troubleshooting purposes. The url may contain a region suffix (e.g. "-eastus") if we're using location specific endpoints.

function getWriteEndpoint()

Returns

Promise<string>

offer(string)

Used for reading, or updating a existing offer by id.

function offer(id: string)

Parameters

id
string

The id of the offer.

Returns