0
votes

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.

2
@Matias: So strange. I have tried the 3 dots and I only had 2 options available. Delete collection and new document. I never see the other options you see. I downloaded my emulator from azure website as well. - Phoenix Yu

2 Answers

1
votes

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

1
votes

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