IDocumentClient.CreateUserDefinedFunctionAsync Method

Definition

Overloads

CreateUserDefinedFunctionAsync(String, UserDefinedFunction, RequestOptions)

Creates a user defined function as an asychronous operation in the Azure Cosmos DB service.

CreateUserDefinedFunctionAsync(Uri, UserDefinedFunction, RequestOptions)

Creates a user defined function as an asychronous operation in the Azure Cosmos DB service.

CreateUserDefinedFunctionAsync(String, UserDefinedFunction, RequestOptions)

Creates a user defined function as an asychronous operation in the Azure Cosmos DB service.

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

Parameters

collectionLink
String

The link of the DocumentCollection to create the user defined function in. E.g. dbs/db_rid/colls/col_rid/

function
UserDefinedFunction

The UserDefinedFunction object to create.

options
RequestOptions

(Optional) Any RequestOptionsfor this request.

Returns

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

Exceptions

If either collectionLink or function 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 user defined function or that the Body was malformed.
403Forbidden - You have reached your quota of user defined functions for the collection supplied. Contact support to have this quota increased.
409Conflict - This means a UserDefinedFunction with an id matching the id you supplied already existed.
413RequestEntityTooLarge - This means the body of the UserDefinedFunction you tried to create was too large.

Examples

//Create a user defined function that converts a string to upper case
UserDefinedFunction udf = client.CreateUserDefinedFunctionAsync(collectionLink, new UserDefinedFunction
{
   Id = "ToUpper",
   Body = @"function toUpper(input) {
                       return input.toUpperCase();
                    }",
});

See also

Applies to

CreateUserDefinedFunctionAsync(Uri, UserDefinedFunction, RequestOptions)

Creates a user defined function as an asychronous operation in the Azure Cosmos DB service.

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

Parameters

documentCollectionUri
Uri

The URI of the document collection to create the user defined function in.

options
RequestOptions

(Optional) The RequestOptions for the request.

Returns

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

Applies to