Udostępnij za pośrednictwem


DocumentClient.CreateDocumentCollectionIfNotExistsAsync Method

Definition

Overloads

CreateDocumentCollectionIfNotExistsAsync(Uri, DocumentCollection, RequestOptions)

Creates(if doesn't exist) or gets(if already exists) a collection as an asychronous operation in the Azure Cosmos DB service.

CreateDocumentCollectionIfNotExistsAsync(String, DocumentCollection, RequestOptions)

Creates (if doesn't exist) or gets (if already exists) a collection as an asychronous operation in the Azure Cosmos DB service. You can check the status code from the response to determine whether the collection was newly created (201) or existing collection was returned (200).

CreateDocumentCollectionIfNotExistsAsync(Uri, DocumentCollection, RequestOptions)

Creates(if doesn't exist) or gets(if already exists) 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>> CreateDocumentCollectionIfNotExistsAsync (Uri databaseUri, Microsoft.Azure.Documents.DocumentCollection documentCollection, Microsoft.Azure.Documents.Client.RequestOptions options = default);
abstract member CreateDocumentCollectionIfNotExistsAsync : Uri * Microsoft.Azure.Documents.DocumentCollection * Microsoft.Azure.Documents.Client.RequestOptions -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.DocumentCollection>>
override this.CreateDocumentCollectionIfNotExistsAsync : 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 CreateDocumentCollectionIfNotExistsAsync (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) 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.

Implements

Applies to

CreateDocumentCollectionIfNotExistsAsync(String, DocumentCollection, RequestOptions)

Creates (if doesn't exist) or gets (if already exists) a collection as an asychronous operation in the Azure Cosmos DB service. You can check the status code from the response to determine whether the collection was newly created (201) or existing collection was returned (200).

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.DocumentCollection>> CreateDocumentCollectionIfNotExistsAsync (string databaseLink, Microsoft.Azure.Documents.DocumentCollection documentCollection, Microsoft.Azure.Documents.Client.RequestOptions options = default);
abstract member CreateDocumentCollectionIfNotExistsAsync : string * Microsoft.Azure.Documents.DocumentCollection * Microsoft.Azure.Documents.Client.RequestOptions -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.DocumentCollection>>
override this.CreateDocumentCollectionIfNotExistsAsync : 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 CreateDocumentCollectionIfNotExistsAsync (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.

Implements

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

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.CreateDocumentCollectionIfNotExistsAsync(databaseLink,
        new DocumentCollection { Id = "My Collection" },
        new RequestOptions { OfferThroughput = 10000} );
}

See also

Applies to