I am trying to create a stored procedure that my app can call to run operations on a SQL cosmos DB in azure. I'm developing this using the Azure portal.
I generated a sample procedure, which is shown below.
// SAMPLE STORED PROCEDURE
function sample(prefix) {
var collection = getContext().getCollection();
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
'SELECT * FROM root r',
function (err, feed, options) {
if (err) throw err;
// Check the feed and if empty, set the body to 'no docs found',
// else take 1st element from feed
if (!feed || !feed.length) {
var response = getContext().getResponse();
response.setBody('no docs found');
}
else {
var response = getContext().getResponse();
var body = { prefix: prefix, feed: feed[0] };
response.setBody(JSON.stringify(body));
}
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
When I run this, I get no results, but I created a single document in the documents section under the same tree as this stored procedure. When I run the stored procedure, I get no results. What am I doing wrong?