Options
All
  • Public
  • Public/Protected
  • All
Menu

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.

example

Instantiate a client and create a new database

const client = new CosmosClient({endpoint: "<URL HERE>", auth: {masterKey: "<KEY HERE>"}});
await client.databases.create({id: "<datbase name here>"});
example

Instantiate a client with custom Connection Policy

const connectionPolicy = new ConnectionPolicy();
connectionPolicy.RequestTimeout = 10000;
const client = new CosmosClient({
   endpoint: "<URL HERE>",
   auth: {masterKey: "<KEY HERE>"},
   connectionPolicy
});

Hierarchy

  • CosmosClient

Index

Constructors

constructor

Properties

databases

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.

example

Create a new database

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

offers

offers: Offers

Used for querying & reading all offers.

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

Methods

database

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

    example

    Create a new container off of an existing database

    const container = client.database("<database id>").containers.create("<container id>");
    example

    Delete an existing database

    await client.database("<id here>").delete();

    Parameters

    • id: string

      The id of the database.

    Returns Database

getDatabaseAccount

getReadEndpoint

  • getReadEndpoint(): 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<string>

getWriteEndpoint

  • getWriteEndpoint(): Promise<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>

offer

  • offer(id: string): Offer
  • Used for reading, or updating a existing offer by id.

    Parameters

    • id: string

      The id of the offer.

    Returns Offer

Generated using TypeDoc