Phoenix Yu
Phoenix Yu

Reputation: 61

Create stored procedure in DocumentDB Emulator

Update: I downloaded the emulator again and did a repair and the options show up again. Resolved.

can anyone please tell me if it is possible to create stored procedures in DocumentDB emulator? I know I can do it in the real DocumentDB on Azure. However, I can't seem to be able to find the script panel anywhere in the emulator. I google around and I can't find any answer either. According to the website, I should be able to create stored procs using the emulator. Very strange.

Upvotes: 0

Views: 798

Answers (2)

Matias Quaranta
Matias Quaranta

Reputation: 15603

You can create Stored procedures, User Defined Functions & Triggers from the Cosmos DB Emulator UI. Just click on the ... dots that appear when you hover over the collection to open the context menu or right click over it.

Azure Cosmos DB Emulator capture

Upvotes: 1

Fei Han
Fei Han

Reputation: 27793

We can create stored procedure using the Azure Cosmos DB Emulator, the following code works fine on my side.

Register stored procedure

DocumentClient client = new DocumentClient(
    new Uri("https://localhost:8081"),
    "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");
var TestSproc = new StoredProcedure
{
    Id = "SayHello",
    Body = @"function SayHello() { 
    var response = getContext().getResponse();
    response.setBody('hello');}"
};
StoredProcedure createdStoredProcedure = await client.CreateStoredProcedureAsync(UriFactory.CreateDocumentCollectionUri("testdb", "testcoll"), TestSproc);

Execute stored procedure

StoredProcedureResponse<object> result = await client.ExecuteStoredProcedureAsync<object>(
    UriFactory.CreateStoredProcedureUri("testdb", "testcoll", "SayHello"));

result.Response.ToString();

Result

enter image description here

Upvotes: 1

Related Questions