Share via


Database.CreateContainerAsync Method

Definition

Overloads

CreateContainerAsync(ContainerProperties, ThroughputProperties, RequestOptions, CancellationToken)

Creates a container as an asynchronous operation in the Azure Cosmos service.

CreateContainerAsync(ContainerProperties, Nullable<Int32>, RequestOptions, CancellationToken)

Creates a container as an asynchronous operation in the Azure Cosmos service.

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

Creates a container as an asynchronous operation in the Azure Cosmos service.

CreateContainerAsync(ContainerProperties, ThroughputProperties, RequestOptions, CancellationToken)

Source:
Database.cs

Creates a container as an asynchronous operation in the Azure Cosmos service.

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse> CreateContainerAsync (Microsoft.Azure.Cosmos.ContainerProperties containerProperties, Microsoft.Azure.Cosmos.ThroughputProperties throughputProperties, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateContainerAsync : 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 CreateContainerAsync (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.

Examples

ContainerProperties containerProperties = new ContainerProperties()
{
    Id = Guid.NewGuid().ToString(),
    PartitionKeyPath = "/pk",
    IndexingPolicy = new IndexingPolicy()
   {
        Automatic = false,
        IndexingMode = IndexingMode.Lazy,
   }
};

ContainerResponse response = await this.cosmosDatabase.CreateContainerAsync(
    containerProperties,
    ThroughputProperties.CreateAutoscaleThroughput(10000));

Applies to

CreateContainerAsync(ContainerProperties, Nullable<Int32>, RequestOptions, CancellationToken)

Source:
Database.cs

Creates a container as an asynchronous operation in the Azure Cosmos service.

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse> CreateContainerAsync (Microsoft.Azure.Cosmos.ContainerProperties containerProperties, int? throughput = default, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateContainerAsync : Microsoft.Azure.Cosmos.ContainerProperties * Nullable<int> * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse>
Public MustOverride Function CreateContainerAsync (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.

throughput
Nullable<Int32>

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

Examples

ContainerProperties containerProperties = new ContainerProperties()
{
    Id = Guid.NewGuid().ToString(),
    PartitionKeyPath = "/pk",
    IndexingPolicy = new IndexingPolicy()
   {
        Automatic = false,
        IndexingMode = IndexingMode.Lazy,
   }
};

ContainerResponse response = await this.cosmosDatabase.CreateContainerAsync(containerProperties);

See also

Applies to

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

Source:
Database.cs

Creates a container as an asynchronous operation in the Azure Cosmos service.

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse> CreateContainerAsync (string id, string partitionKeyPath, int? throughput = default, Microsoft.Azure.Cosmos.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateContainerAsync : string * string * Nullable<int> * Microsoft.Azure.Cosmos.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse>
Public MustOverride Function CreateContainerAsync (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

throughput
Nullable<Int32>

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

Examples

ContainerResponse response = await this.cosmosDatabase.CreateContainerAsync(Guid.NewGuid().ToString(), "/pk");

See also

Applies to