I am using Azure Cosmos DB SQL API . I have written stored procedure will get the data and keeps in response API feed .
Failed to execute stored procedure testProcedure for collection iotcollection: {"code":400,"body":"{\"code\":\"BadRequest\",\"message\":\"Message: {\\"Errors\\":[\\"Encountered exception while executing function. Exception = Error: Out of memory\\r\\nStack trace: undefined\\"]}\r\nActivityId: c286cbb6-34c1-4929-a148-915544b20ce6, Request URI: /apps/59d3b9ef-17ca-4bbf-8a11-39d0199a8d29/services/1b26e00f-1f51-4d34-88ec-4090b8e7db00/partitions/45a313b7-2cf2-419e-9885-48bf9cfe6277/replicas/131862936473830809p/, RequestStats: \r\nRequestStartTime: 2018-11-10T05:46:36.4852333Z, Number of regions attempted: 1\r\n, SDK: Microsoft.Azure.Documents.Common/2.1.0.0\"}","activityId":"c286cbb6-34c1-4929-a148-915544b20ce6"}
My stored procedure is very simple one I just wanted to see how many records i can fetch from cosmos DB at given time and send as response.
// SAMPLE STORED PROCEDURE
function sample(prefix) {
var collection = getContext().getCollection();
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
'SELECT r.data 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] };
var str = 'str';
for ( var i =0 ; i < 100 ; i = i +1 ){
str = str + str ;
body .str = feed[0];
}
response.setBody(JSON.stringify(body));
}
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
I'm sure the reason of
Out-Of-Memory
error is thestr
string is too long during your loop. It seems that thestr
string is useless for your test which is not added into response.Please remove it and the sample stored procedure will work fine.