How to debug CosmosDB stored procedure easily

CosmosDB stored procedure, written in javascript, sometimes can be difficult to debug. One easy way is to do console log like normal javascript and debug the code with those logs.

Console logs are by default disabled in CosmosDB stored procedures. You have to enable them first before making the request to CosmosDB.

var options = new RequestOptions()
          PartitionKey = new PartitionKey(partitionKey.ToString()),
          EnableScriptLogging = true

StoredProcedureResponse<TValue> result = await 

Here, TValue = your custom response object

You can now access the console log in your stored procedure written in javascript inside StoredProcedureResponse.ScriptLog like this


Leave a Reply

Your email address will not be published. Required fields are marked *