Package version:

Class CosmosClient

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.

const client = new CosmosClient({endpoint: "<URL HERE>", key: "<KEY HERE>"});
await client.databases.create({id: "<database name here>"});
const client = new CosmosClient({
endpoint: "<URL HERE>",
key: "<KEY HERE>",
connectionPolicy: {
requestTimeout: 10000,
},
});

Constructors

Properties

databases: 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.

const {resource: databaseDefinition, database} = await client.databases.create({id: "<name here>"});
offers: Offers

Used for querying & reading all offers.

Use .offer(id) to read, or replace existing offers.

Methods

  • 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 Database object.

    Parameters

    • id: string

      The id of the database.

    Returns Database

    const container = client.database("<database id>").containers.create("<container id>");
    
    await client.database("<id here>").delete();
    
  • 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.

    Returns Promise<string>

  • 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.

    Returns Promise<readonly string[]>

  • 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.

    Returns Promise<string>

  • Gets the known write endpoints. Useful for troubleshooting purposes.

    The urls may contain a region suffix (e.g. "-eastus") if we're using location specific endpoints.

    Returns Promise<readonly string[]>