Skip to content Skip to sidebar Skip to footer

Microsoft Azure Cosmostdb Script Explorer Console.log

I am trying to debug a stored procedure or a script written in Microsoft Azure CosmosDB 'Script Explorer' using javascript. I put several console.log() messages so that I could tra

Solution 1:

I've found a getScriptLog method to get the console. Log () statement in the Azure Cosmos DB Stored Proceduce official documentation.

I created a stored procudure in my Azure Cosmos DB Collection as below:

enter image description here

I don't know what language SDK you are currently using, please refer to the Java SDK sample code as below which could also be implemented in other SDKs.

//query exist stored procedure in collection
StoredProcedure createdSproc =documentClient.readStoredProcedure("dbs/" + DATABASE_ID + "/colls/" + COLLECTION_ID +"/sprocs/"+"test", null).getResource();
//print query result
System.out.println(createdSproc.toString());
try {
    //set Request options
    RequestOptions options=new RequestOptions();
    //enable script logging  true
    options.setScriptLoggingEnabled(true);
    //execute stored procedure
    StoredProcedureResponse spr = documentClient.executeStoredProcedure(createdSproc.getSelfLink(), options,
            null);
    System.out.println(spr.toString());
    System.out.println("status code: "+spr.getStatusCode());
    //print script log
    System.out.println("Scrpit Log: "+ spr.getScriptLog());
    System.out.println("Response body: "+spr.getResponseAsString());
} catch (DocumentClientException e) {
    e.printStackTrace();
}

Output:

enter image description here

Please note that this code is necessary to print console.log:

options.setScriptLoggingEnabled(true);

Post a Comment for "Microsoft Azure Cosmostdb Script Explorer Console.log"