0
votes

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}

1
Please refrain from asking the same question more than once with tweaks to the verbiage. This is the third time you’ve pasted the same code and asked about oversized responses. - Josh
Hi,Amjath,does my answer helps you? - Jay Gong

1 Answers

0
votes

Per my experience, {pageSize : -1} setting is not recommanded strongly when your data is too huge in cosmos db query operation. Continuation token(namely x-ms-continuation-token in cosmos db rest api) need to be considered into your business. Please refer to my previous case:CosmosDB stored procedure not returning all documents.

As you said, later on after 5 min executed same procedure and same parameters it was showing error of too large page size. The size limit is total response which including other Response Headers,not only the body part. In addition, the query operation returns maximum results based on current performance if you set {pageSize : -1}. It's not fixed.