I am writing Azure Cosmos DB stored procedure in azure portal , I am checking the what is max size response it can give initially it gave me 4.8 MB response later on any size more that it was showing error of message size is too large . Later on after 5 min executed same procedure and same parameters it was showing error of too large page size.
// 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.truckSerialNo FROM root r',{pageSize : -1},
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 {
console.log(feed.length);
var response = getContext().getResponse();
var body = { prefix: prefix, feed: feed };
var str = {};
str.x1 = body ;
str.x2 = body ;
response.setBody(JSON.stringify(str));
}
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
and error
Failed to execute stored procedure testProcedure for collection iotcollection: {"code":400,"body":"{\"code\":\"BadRequest\",\"message\":\"Message: {\\"Errors\\":[\\"Encountered exception while executing function. Exception = Error: Resulting message would be too large because of \\\\"Body\\\\". Return from script with current message and use continuation token to call the script again or modify your script.\\r\\nStack trace: Error: Resulting message would be too large because of \\\\"Body\\\\". Return from script with current message and use continuation token to call the script again or modify your script.\\n at validateSize (bulkUpsert_v_1_0.js:177:25)\\n at setValueInternal (bulkUpsert\\"]}\r\nActivityId: d61226ab-4d5e-4a3d-aa09-83351649ce4c, 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-10T06:41:26.3320532Z, Number of regions attempted: 1\r\n, SDK: Microsoft.Azure.Documents.Common/2.1.0.0\"}","activityId":"d61226ab-4d5e-4a3d-aa09-83351649ce4c","substatus":413}