IDocumentClient.UpsertTriggerAsync Method

Definition

Overloads

UpsertTriggerAsync(String, Trigger, RequestOptions)

Upserts a trigger as an asychronous operation in the Azure Cosmos DB service.

UpsertTriggerAsync(Uri, Trigger, RequestOptions)

Upserts a trigger as an asychronous operation in the Azure Cosmos DB service.

UpsertTriggerAsync(String, Trigger, RequestOptions)

Upserts a trigger as an asychronous operation in the Azure Cosmos DB service.

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

Parameters

collectionLink
String

The link of the DocumentCollection to upsert the trigger in. E.g. dbs/db_rid/colls/col_rid/

trigger
Trigger

The Trigger object to upsert.

options
RequestOptions

(Optional) Any RequestOptionsfor this request.

Returns

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

Exceptions

If either collectionLink or trigger 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 request supplied. It is likely that an Id was not supplied for the new trigger or that the Body was malformed.
403Forbidden - You have reached your quota of triggers for the collection supplied. Contact support to have this quota increased.
409Conflict - This means a Trigger with an id matching the id you supplied already existed.
413RequestEntityTooLarge - This means the body of the Trigger you tried to upsert was too large.

Examples

//Upsert a trigger that validates the contents of a document as it is created and adds a 'timestamp' property if one was not found.
Trigger trig = await client.UpsertTriggerAsync(collectionLink, new Trigger
{
    Id = "ValidateDocuments",
    Body = @"function validate() {
                        var context = getContext();
                        var request = context.getRequest();                                                             
                        var documentToCreate = request.getBody();

                        // validate properties
                        if (!('timestamp' in documentToCreate)) {
                            var ts = new Date();
                            documentToCreate['timestamp'] = ts.getTime();
                        }

                        // update the document that will be created
                        request.setBody(documentToCreate);
                      }",
    TriggerType = TriggerType.Pre,
    TriggerOperation = TriggerOperation.Create
});

See also

Applies to

UpsertTriggerAsync(Uri, Trigger, RequestOptions)

Upserts a trigger as an asychronous operation in the Azure Cosmos DB service.

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

Parameters

documentCollectionUri
Uri

The URI of the document collection to upsert the trigger in.

trigger
Trigger

The Trigger object.

options
RequestOptions

(Optional) The RequestOptions for the request.

Returns

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

Applies to