Sdílet prostřednictvím


IDocumentClient.CreateDocumentCollectionAsync Method

Definition

Overloads

CreateDocumentCollectionAsync(String, DocumentCollection, RequestOptions)

Creates a collection as an asychronous operation in the Azure Cosmos DB service.

CreateDocumentCollectionAsync(Uri, DocumentCollection, RequestOptions)

Creates a collection as an asychronous operation in the Azure Cosmos DB service.

CreateDocumentCollectionAsync(String, DocumentCollection, RequestOptions)

Creates a collection as an asychronous operation in the Azure Cosmos DB service.

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.DocumentCollection>> CreateDocumentCollectionAsync (string databaseLink, Microsoft.Azure.Documents.DocumentCollection documentCollection, Microsoft.Azure.Documents.Client.RequestOptions options = default);
abstract member CreateDocumentCollectionAsync : string * Microsoft.Azure.Documents.DocumentCollection * Microsoft.Azure.Documents.Client.RequestOptions -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.DocumentCollection>>
Public Function CreateDocumentCollectionAsync (databaseLink As String, documentCollection As DocumentCollection, Optional options As RequestOptions = Nothing) As Task(Of ResourceResponse(Of DocumentCollection))

Parameters

databaseLink
String

The link of the database to create the collection in. E.g. dbs/db_rid/.

documentCollection
DocumentCollection

The DocumentCollection object.

options
RequestOptions

(Optional) Any RequestOptions you wish to provide when creating a Collection. E.g. RequestOptions.OfferThroughput = 400.

Returns

The DocumentCollection that was created contained within a Task object representing the service response for the asynchronous operation.

Exceptions

If either databaseLink or documentCollection is not set.

Represents a consolidation of failures that occured during async processing. Look within InnerExceptions to find the actual exception(s).

This exception can encapsulate many different types of errors. To determine the specific error always look at the StatusCode property. Some common codes you may get when creating a collection are:

StatusCodeReason for exception
400BadRequest - This means something was wrong with the request supplied. It is likely that an id was not supplied for the new collection.
403Forbidden - This means you attempted to exceed your quota for collections. Contact support to have this quota increased.
409Conflict - This means a DocumentCollection with an id matching the id you supplied already existed.

Examples

using (IDocumentClient client = new DocumentClient(new Uri("service endpoint"), "auth key"))
{
    //Create a new collection with an OfferThroughput set to 10000
    //Not passing in RequestOptions.OfferThroughput will result in a collection with the default OfferThroughput set.
    DocumentCollection coll = await client.CreateDocumentCollectionAsync(databaseLink,
        new DocumentCollection { Id = "My Collection" },
        new RequestOptions { OfferThroughput = 10000} );
}

See also

Applies to

CreateDocumentCollectionAsync(Uri, DocumentCollection, RequestOptions)

Creates a collection as an asychronous operation in the Azure Cosmos DB service.

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.DocumentCollection>> CreateDocumentCollectionAsync (Uri databaseUri, Microsoft.Azure.Documents.DocumentCollection documentCollection, Microsoft.Azure.Documents.Client.RequestOptions options = default);
abstract member CreateDocumentCollectionAsync : Uri * Microsoft.Azure.Documents.DocumentCollection * Microsoft.Azure.Documents.Client.RequestOptions -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.DocumentCollection>>
Public Function CreateDocumentCollectionAsync (databaseUri As Uri, documentCollection As DocumentCollection, Optional options As RequestOptions = Nothing) As Task(Of ResourceResponse(Of DocumentCollection))

Parameters

databaseUri
Uri

The URI of the database to create the collection in.

documentCollection
DocumentCollection

The DocumentCollection object.

options
RequestOptions

(Optional) The RequestOptions for the request.

Returns

The task object representing the service response for the asynchronous operation.

Applies to