DocumentClient.CreateDocumentAsync Method

Definition

Overloads

CreateDocumentAsync(String, Object, RequestOptions, Boolean)

Creates a Document as an asychronous operation in the Azure DocumentDB database service.

CreateDocumentAsync(Uri, Object, RequestOptions, Boolean)

Creates a document as an asychronous operation in the Azure DocumentDB database service.

CreateDocumentAsync(String, Object, RequestOptions, Boolean)

Creates a Document as an asychronous operation in the Azure DocumentDB database service.

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>> CreateDocumentAsync (string documentsFeedOrDatabaseLink, object document, Microsoft.Azure.Documents.Client.RequestOptions options = null, bool disableAutomaticIdGeneration = false);
Parameters
documentsFeedOrDatabaseLink
String

The link of the DocumentCollection to create the document in. E.g. dbs/db_rid/colls/coll_rid/

document
Object

The document object to create.

options
RequestOptions

(Optional) Any request options you wish to set. E.g. Specifying a Trigger to execute when creating the document. RequestOptions

disableAutomaticIdGeneration
Boolean

(Optional) Disables the automatic id generation, If this is True the system will throw an exception if the id property is missing from the Document.

Returns

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

Exceptions

If either documentsFeedOrDatabaseLink or document 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 Document are:

StatusCodeReason for exception
400BadRequest - This means something was wrong with the document supplied. It is likely that disableAutomaticIdGeneration was true and an id was not supplied
403Forbidden - This likely means the collection in to which you were trying to create the document is full.
409Conflict - This means a Document with an id matching the id field of document already existed
413RequestEntityTooLarge - This means the Document exceeds the current max entity size. Consult documentation for limits and quotas.
429TooManyRequests - This means you have exceeded the number of request units per second. Consult the DocumentClientException.RetryAfter value to see how long you should wait before retrying this operation.

CreateDocumentAsync(Uri, Object, RequestOptions, Boolean)

Creates a document as an asychronous operation in the Azure DocumentDB database service.

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>> CreateDocumentAsync (Uri documentCollectionUri, object document, Microsoft.Azure.Documents.Client.RequestOptions options = null, bool disableAutomaticIdGeneration = false);
Parameters
documentCollectionUri
Uri

the URI of the document collection to create the document in.

document
Object

the document object.

options
RequestOptions

The request options for the request.

disableAutomaticIdGeneration
Boolean

Disables the automatic id generation, will throw an exception if id is missing.

Returns

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