Share via


DocumentClient.CreateStoredProcedureAsync Method

Definition

Overloads

CreateStoredProcedureAsync(String, StoredProcedure, RequestOptions)

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

CreateStoredProcedureAsync(Uri, StoredProcedure, RequestOptions)

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

CreateStoredProcedureAsync(String, StoredProcedure, RequestOptions)

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

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

Parameters

collectionLink
String

The link of the collection to create the stored procedure in. E.g. dbs/db_rid/colls/col_rid/

storedProcedure
StoredProcedure

The StoredProcedure object to create.

options
RequestOptions

(Optional) Any RequestOptionsfor this request.

Returns

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

Implements

Exceptions

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

Examples

//Create a new stored procedure called "HelloWorldSproc" that takes in a single param called "name".
StoredProcedure sproc = await client.CreateStoredProcedureAsync(collectionLink, new StoredProcedure
{
   Id = "HelloWorldSproc",
   Body = @"function (name){
               var response = getContext().getResponse();
               response.setBody('Hello ' + name);
            }"
});

See also

Applies to

CreateStoredProcedureAsync(Uri, StoredProcedure, RequestOptions)

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

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

Parameters

documentCollectionUri
Uri

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

storedProcedure
StoredProcedure

the Microsoft.Azure.Documents.StoredProcedure object.

options
RequestOptions

The request options for the request.

Returns

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

Implements

Applies to