Condividi tramite


CosmosClient.CreateDatabaseIfNotExistsAsync Method

Definition

Overloads

CreateDatabaseIfNotExistsAsync(String, Nullable<Int32>, RequestOptions, CancellationToken)

Check if a database exists, and if it doesn't, create it. Only the database id is used to verify if there is an existing database. Other database properties such as throughput are not validated and can be different then the passed properties.

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.

CreateDatabaseIfNotExistsAsync(String, ThroughputProperties, RequestOptions, CancellationToken)

Check if a database exists, and if it doesn't, create it. Only the database id is used to verify if there is an existing database. Other database properties such as throughput are not validated and can be different then the passed properties.

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.

CreateDatabaseIfNotExistsAsync(String, Nullable<Int32>, RequestOptions, CancellationToken)

Source:
CosmosClient.cs

Check if a database exists, and if it doesn't, create it. Only the database id is used to verify if there is an existing database. Other database properties such as throughput are not validated and can be different then the passed properties.

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.

public virtual System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.DatabaseResponse> CreateDatabaseIfNotExistsAsync (string id, int? throughput = default, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateDatabaseIfNotExistsAsync : string * Nullable<int> * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.DatabaseResponse>
override this.CreateDatabaseIfNotExistsAsync : string * Nullable<int> * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.DatabaseResponse>
Public Overridable Function CreateDatabaseIfNotExistsAsync (id As String, Optional throughput As Nullable(Of Integer) = Nothing, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of DatabaseResponse)

Parameters

id
String

The database id.

throughput
Nullable<Int32>

(Optional) The throughput provisioned for a database in measurement of Request Units per second in the Azure Cosmos DB service.

requestOptions
RequestOptions

(Optional) A set of additional options that can be set.

cancellationToken
CancellationToken

(Optional) CancellationToken representing request cancellation.

Returns

A Task containing a DatabaseResponse which wraps a DatabaseProperties containing the resource record.

StatusCodeCommon success StatusCodes for the CreateDatabaseIfNotExistsAsync operation
201Created - New database is created.
200OK- This means the database already exists.

Applies to

CreateDatabaseIfNotExistsAsync(String, ThroughputProperties, RequestOptions, CancellationToken)

Source:
CosmosClient.cs

Check if a database exists, and if it doesn't, create it. Only the database id is used to verify if there is an existing database. Other database properties such as throughput are not validated and can be different then the passed properties.

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.

public virtual System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.DatabaseResponse> CreateDatabaseIfNotExistsAsync (string id, Microsoft.Azure.Cosmos.ThroughputProperties throughputProperties, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateDatabaseIfNotExistsAsync : string * Microsoft.Azure.Cosmos.ThroughputProperties * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.DatabaseResponse>
override this.CreateDatabaseIfNotExistsAsync : string * Microsoft.Azure.Cosmos.ThroughputProperties * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.DatabaseResponse>
Public Overridable Function CreateDatabaseIfNotExistsAsync (id As String, throughputProperties As ThroughputProperties, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of DatabaseResponse)

Parameters

id
String

The database id.

throughputProperties
ThroughputProperties

The throughput provisioned for a database in measurement of Request Units per second in the Azure Cosmos DB service.

requestOptions
RequestOptions

(Optional) A set of additional options that can be set.

cancellationToken
CancellationToken

(Optional) CancellationToken representing request cancellation.

Returns

A Task containing a DatabaseResponse which wraps a DatabaseProperties containing the resource record.

StatusCodeCommon success StatusCodes for the CreateDatabaseIfNotExistsAsync operation
201Created - New database is created.
200OK - This means the database already exists.

Applies to