Database class

Operations for reading or deleting an existing database.

See Databases for creating new databases, and reading/querying all databases; use client.databases.

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 database.read() before every single item.read() call, to ensure the database exists; do this once on application start up.

Constructors

Database(CosmosClient, string, ClientContext)

Returns a new Database instance. Note: the intention is to get this object from CosmosClient via client.database(id), not to instantiate it yourself.

Properties

client
containers

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

Example

Create a new container

const {body: containerDefinition, container} = await client.database("<db id>").containers.create({id: "<container id>"});
id
url

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

users

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

Methods

container(string)

Used to read, replace, or delete a specific, existing Database by id. Use .containers creating new containers, or querying/reading all containers.

Example

Delete a container

await client.database("<db id>").container("<container id>").delete();
delete(RequestOptions)

Delete the given Database.

read(RequestOptions)

Read the definition of the given Database.

readOffer(RequestOptions)

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

user(string)

Used to read, replace, or delete a specific, existing User by id. Use .users for creating new users, or querying/reading all users.

Constructor Details

Database(CosmosClient, string, ClientContext)

Returns a new Database instance. Note: the intention is to get this object from CosmosClient via client.database(id), not to instantiate it yourself.

new Database(client: CosmosClient, id: string, clientContext: ClientContext)

Parameters

client
CosmosClient
id

string

clientContext

ClientContext

Property Details

client

client: CosmosClient

Property Value

containers

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

Example

Create a new container

const {body: containerDefinition, container} = await client.database("<db id>").containers.create({id: "<container id>"});
containers: Containers

Property Value

id

id: string

Property Value

string

url

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

string url

Property Value

string

users

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

users: Users

Property Value

Method Details

container(string)

Used to read, replace, or delete a specific, existing Database by id. Use .containers creating new containers, or querying/reading all containers.

Example

Delete a container

await client.database("<db id>").container("<container id>").delete();
function container(id: string): Container

Parameters

id

string

Returns

delete(RequestOptions)

Delete the given Database.

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

Parameters

options
RequestOptions

Returns

Promise<DatabaseResponse>

read(RequestOptions)

Read the definition of the given Database.

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

Parameters

options
RequestOptions

Returns

Promise<DatabaseResponse>

readOffer(RequestOptions)

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

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

Parameters

options
RequestOptions

Returns

Promise<OfferResponse>

user(string)

Used to read, replace, or delete a specific, existing User by id. Use .users for creating new users, or querying/reading all users.

function user(id: string): User

Parameters

id

string

Returns