I'm new to Cosmos DB stored procedure. As introduced, cosmos stored procedure is written with Javascript, and it's unable to debug by setting up the break point, so we'll have to use console.log(...)
to watch element content inside the stored procedure. Here is one of my example, which is to retrieve an item from my collection based on the input parameter prefix (the 'id' property in my item), and using javascript-query-api
function example(prefix) {
//not working with ','
//console.log('input prefix: ', prefix);
//this works with '+'
console.log('input prefix: ' + prefix);
var collection = getContext().getCollection();
//cannot view what's collection represents
console.log('collection:' + JSON.stringify(collection));
collection.chain().filter(function (doc) {
//un-comment below will make the console log blank...
//console.log('inside filter prefix: ' + prefix);
return doc.id == prefix;
}).map(function (doc) {
return {
id: doc.id,
price: doc.price
}
}).value();
}
Here is my console.log window
My console.log won't do a line break or working with comma ',':
So a summary of couple of issues I had are:
console.log
inside the stored procedure won't work with comma -,
but only works with colon -:
console.log
won't do a line break... even I add\n
inside...- I cannot get what's really inside the
collection
object even I've deserialized it, as you can see from screenshot it's shown as {\"spatial\":{}} - If I wanted to look into what the input parameter -
prefix
passing inside my filter function, when I un-comment myconsole.log('inside filter prefix: ' + prefix);
, then my console log screen will show only an empty string somehow which is really ... - Adding more details for data schema, partition key and stored procedure execution detail
Data schema:
Stored procedure execution detail:
Stored procedure result and console.log: