Database.CreateContainerIfNotExistsAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
CreateContainerIfNotExistsAsync(ContainerProperties, ThroughputProperties, RequestOptions, CancellationToken) |
Check if a container exists, and if it doesn't, create it. Only the container id is used to verify if there is an existing container. Other container properties such as throughput are not validated and can be different then the passed properties. |
CreateContainerIfNotExistsAsync(ContainerProperties, Nullable<Int32>, RequestOptions, CancellationToken) |
Check if a container exists, and if it doesn't, create it. Only the container id is used to verify if there is an existing container. Other container properties such as throughput are not validated and can be different then the passed properties. |
CreateContainerIfNotExistsAsync(String, String, Nullable<Int32>, RequestOptions, CancellationToken) |
Check if a container exists, and if it doesn't, create it. This will make a read operation, and if the container is not found it will do a create operation. |
CreateContainerIfNotExistsAsync(ContainerProperties, ThroughputProperties, RequestOptions, CancellationToken)
- Source:
- Database.cs
Check if a container exists, and if it doesn't, create it. Only the container id is used to verify if there is an existing container. Other container properties such as throughput are not validated and can be different then the passed properties.
public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse> CreateContainerIfNotExistsAsync (Microsoft.Azure.Cosmos.ContainerProperties containerProperties, Microsoft.Azure.Cosmos.ThroughputProperties throughputProperties, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateContainerIfNotExistsAsync : Microsoft.Azure.Cosmos.ContainerProperties * Microsoft.Azure.Cosmos.ThroughputProperties * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse>
Public MustOverride Function CreateContainerIfNotExistsAsync (containerProperties As ContainerProperties, throughputProperties As ThroughputProperties, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ContainerResponse)
Parameters
- containerProperties
- ContainerProperties
The ContainerProperties object.
- throughputProperties
- ThroughputProperties
(Optional) The throughput provisioned for a container in measurement of Requests Units per second in the Azure Cosmos DB service.
- requestOptions
- RequestOptions
(Optional) The options for the request.
- cancellationToken
- CancellationToken
(Optional) CancellationToken representing request cancellation.
Returns
A Task containing a ContainerResponse which wraps a ContainerProperties containing the read resource record.
StatusCode | Common success StatusCodes for the CreateDatabaseIfNotExistsAsync operation |
---|---|
201 | Created - New database is created. |
200 | OK - This means the database already exists. |
Examples
ContainerProperties containerProperties = new ContainerProperties()
{
Id = Guid.NewGuid().ToString(),
PartitionKeyPath = "/pk",
IndexingPolicy = new IndexingPolicy()
{
Automatic = false,
IndexingMode = IndexingMode.Lazy,
}
};
ContainerResponse response = await this.cosmosDatabase.CreateContainerIfNotExistsAsync(
containerProperties,
ThroughputProperties.CreateAutoscaleThroughput(5000));
Applies to
CreateContainerIfNotExistsAsync(ContainerProperties, Nullable<Int32>, RequestOptions, CancellationToken)
- Source:
- Database.cs
Check if a container exists, and if it doesn't, create it. Only the container id is used to verify if there is an existing container. Other container properties such as throughput are not validated and can be different then the passed properties.
public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse> CreateContainerIfNotExistsAsync (Microsoft.Azure.Cosmos.ContainerProperties containerProperties, int? throughput = default, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateContainerIfNotExistsAsync : Microsoft.Azure.Cosmos.ContainerProperties * Nullable<int> * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse>
Public MustOverride Function CreateContainerIfNotExistsAsync (containerProperties As ContainerProperties, Optional throughput As Nullable(Of Integer) = Nothing, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ContainerResponse)
Parameters
- containerProperties
- ContainerProperties
The ContainerProperties object.
(Optional) The throughput provisioned for a container in measurement of Requests Units per second in the Azure Cosmos DB service.
- requestOptions
- RequestOptions
(Optional) The options for the request.
- cancellationToken
- CancellationToken
(Optional) CancellationToken representing request cancellation.
Returns
A Task containing a ContainerResponse which wraps a ContainerProperties containing the read resource record.
StatusCode | Common success StatusCodes for the CreateDatabaseIfNotExistsAsync operation |
---|---|
201 | Created - New database is created. |
200 | OK - This means the database already exists. |
Examples
ContainerProperties containerProperties = new ContainerProperties()
{
Id = Guid.NewGuid().ToString(),
PartitionKeyPath = "/pk",
IndexingPolicy = new IndexingPolicy()
{
Automatic = false,
IndexingMode = IndexingMode.Lazy,
}
};
ContainerResponse response = await this.cosmosDatabase.CreateContainerIfNotExistsAsync(containerProperties);
Applies to
CreateContainerIfNotExistsAsync(String, String, Nullable<Int32>, RequestOptions, CancellationToken)
- Source:
- Database.cs
Check if a container exists, and if it doesn't, create it. This will make a read operation, and if the container is not found it will do a create operation.
public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse> CreateContainerIfNotExistsAsync (string id, string partitionKeyPath, int? throughput = default, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateContainerIfNotExistsAsync : string * string * Nullable<int> * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse>
Public MustOverride Function CreateContainerIfNotExistsAsync (id As String, partitionKeyPath As String, Optional throughput As Nullable(Of Integer) = Nothing, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ContainerResponse)
Parameters
- id
- String
The Cosmos container id
- partitionKeyPath
- String
The path to the partition key. Example: /location
(Optional) The throughput provisioned for a container in measurement of Request Units per second in the Azure Cosmos DB service.
- requestOptions
- RequestOptions
(Optional) The options for the request.
- cancellationToken
- CancellationToken
(Optional) CancellationToken representing request cancellation.
Returns
A Task containing a ContainerResponse which wraps a ContainerProperties containing the read resource record.
Examples
ContainerResponse response = await this.cosmosDatabase.CreateContainerIfNotExistsAsync(Guid.NewGuid().ToString(), "/pk");