Databases class

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

See Database for reading or deleting an existing database; use client.database(id).

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

Properties

client

Methods

create(DatabaseRequest, RequestOptions)

Send a request for creating a database.

A database manages users, permissions and a set of containers. Each Azure Cosmos DB Database Account is able to support multiple independent named databases, with the database being the logical container for data.

Each Database consists of one or more containers, each of which in turn contain one or more documents. Since databases are an administrative resource, the Service Master Key will be required in order to access and successfully complete any action using the User APIs.

createIfNotExists(DatabaseRequest, RequestOptions)

Check if a database exists, and if it doesn't, create it. This will make a read operation based on the id in the body, then if it is not found, a create operation.

A database manages users, permissions and a set of containers. Each Azure Cosmos DB Database Account is able to support multiple independent named databases, with the database being the logical container for data.

Each Database consists of one or more containers, each of which in turn contain one or more documents. Since databases are an an administrative resource, the Service Master Key will be required in order to access and successfully complete any action using the User APIs.

query(string | SqlQuerySpec, FeedOptions)

Queries all databases.

Example

Read all databases to array. * typescript * const querySpec: SqlQuerySpec = { * query: "SELECT * FROM root r WHERE r.id = @db", * parameters: [ * {name: "@db", value: "Todo"} * ] * }; * const {body: databaseList} = await client.databases.query(querySpec).fetchAll(); *

query<T>(string | SqlQuerySpec, FeedOptions)

Queries all databases.

Example

Read all databases to array. * typescript * const querySpec: SqlQuerySpec = { * query: "SELECT * FROM root r WHERE r.id = @db", * parameters: [ * {name: "@db", value: "Todo"} * ] * }; * const {body: databaseList} = await client.databases.query(querySpec).fetchAll(); *

readAll(FeedOptions)

Reads all databases.

Example

Read all databases to array. * typescript * const {body: databaseList} = await client.databases.readAll().fetchAll(); *

Property Details

client

client: CosmosClient

Property Value

Method Details

create(DatabaseRequest, RequestOptions)

Send a request for creating a database.

A database manages users, permissions and a set of containers. Each Azure Cosmos DB Database Account is able to support multiple independent named databases, with the database being the logical container for data.

Each Database consists of one or more containers, each of which in turn contain one or more documents. Since databases are an administrative resource, the Service Master Key will be required in order to access and successfully complete any action using the User APIs.

function create(body: DatabaseRequest, options?: RequestOptions): Promise<DatabaseResponse>

Parameters

body
DatabaseRequest

The DatabaseDefinition that represents the Database to be created.

options
RequestOptions

Use to set options like response page size, continuation tokens, etc.

Returns

Promise<DatabaseResponse>

createIfNotExists(DatabaseRequest, RequestOptions)

Check if a database exists, and if it doesn't, create it. This will make a read operation based on the id in the body, then if it is not found, a create operation.

A database manages users, permissions and a set of containers. Each Azure Cosmos DB Database Account is able to support multiple independent named databases, with the database being the logical container for data.

Each Database consists of one or more containers, each of which in turn contain one or more documents. Since databases are an an administrative resource, the Service Master Key will be required in order to access and successfully complete any action using the User APIs.

function createIfNotExists(body: DatabaseRequest, options?: RequestOptions): Promise<DatabaseResponse>

Parameters

body
DatabaseRequest

The DatabaseDefinition that represents the Database to be created.

options
RequestOptions

Additional options for the request

Returns

Promise<DatabaseResponse>

query(string | SqlQuerySpec, FeedOptions)

Queries all databases.

Example

Read all databases to array. * typescript * const querySpec: SqlQuerySpec = { * query: "SELECT * FROM root r WHERE r.id = @db", * parameters: [ * {name: "@db", value: "Todo"} * ] * }; * const {body: databaseList} = await client.databases.query(querySpec).fetchAll(); *

function query(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<any>

Parameters

query

string | SqlQuerySpec

Query configuration for the operation. See SqlQuerySpec for more info on how to configure a query.

options
FeedOptions

Use to set options like response page size, continuation tokens, etc.

Returns

QueryIterator Allows you to return all databases in an array or iterate over them one at a time. *

query<T>(string | SqlQuerySpec, FeedOptions)

Queries all databases.

Example

Read all databases to array. * typescript * const querySpec: SqlQuerySpec = { * query: "SELECT * FROM root r WHERE r.id = @db", * parameters: [ * {name: "@db", value: "Todo"} * ] * }; * const {body: databaseList} = await client.databases.query(querySpec).fetchAll(); *

function query<T>(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<T>

Parameters

query

string | SqlQuerySpec

Query configuration for the operation. See SqlQuerySpec for more info on how to configure a query.

options
FeedOptions

Use to set options like response page size, continuation tokens, etc.

Returns

QueryIterator Allows you to return all databases in an array or iterate over them one at a time. *

readAll(FeedOptions)

Reads all databases.

Example

Read all databases to array. * typescript * const {body: databaseList} = await client.databases.readAll().fetchAll(); *

function readAll(options?: FeedOptions): QueryIterator<DatabaseDefinition & Resource>

Parameters

options
FeedOptions

Use to set options like response page size, continuation tokens, etc.

Returns

QueryIterator Allows you to return all databases in an array or iterate over them one at a time. *