Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Azure Cosmos DB Stored Procedures?

I am working with Azure Cosmos DB, I am programming the client side in C# (web service) and I'm writing some server side Stored Procedures with java-script.

How can I debug my stored procedure's code?

Thanks,

MAK

like image 588
MAK Avatar asked Dec 17 '17 12:12

MAK


People also ask

How do you debug a stored procedure in Cosmos database?

Azure Cosmos DB stored procedure is JS script running on the server, you can not debug it on your side. However , you can use console. log () to log some key steps in your stored procedure as below. Then use getScriptLog to get the output from stored procedure console.

Can we write stored procedure in Cosmos DB?

Azure Cosmos DB provides language-integrated, transactional execution of JavaScript. When using the SQL API in Azure Cosmos DB, you can write stored procedures, triggers, and user-defined functions (UDFs) in the JavaScript language. You can write your logic in JavaScript that executed inside the database engine.


1 Answers

Azure Cosmos DB stored procedure is JS script running on the server, you can not debug it on your side.

However , you can use console.log () to log some key steps in your stored procedure as below.

enter image description here

Then use getScriptLog to get the output from stored procedure console.log() statements.

Please note that EnableScriptLogging = true is necessary to print console.log:

var response = await client.ExecuteStoredProcedureAsync(
    document.SelfLink,
    new RequestOptions { EnableScriptLogging = true } );
Console.WriteLine(response.ScriptLog);

You could refer to this official doc.

Hope it helps you.

like image 153
Jay Gong Avatar answered Oct 07 '22 02:10

Jay Gong