1

I'm creating a pre-trigger for a Cosmos DB container. The pre-trigger is supposed to fetch all data related to the triggering document id. The incoming_document.items is always returning 100 when there are more than 100 documents expected (which seems to be limited by the query). I tried to set the pageSize property to -1 in the FeedOptions parameters and to use continuation, but it is still giving me 100. How can I fix this to give the total count?

Here is a simplified version of the code (without the continuation, I used a similar code to here):

function trgAddStats() {
    var context = getContext();
    var request = context.getRequest();
    var incoming_document = request.getBody();

    var container = context.getCollection();
    var incoming_document.items = 1;
    var filterQuery = {
        "query": `SELECT t.customer, t.amount FROM Transactions_ds t WHERE t.customer = @customer`,
        "parameters": [{
                "name": "@customer",
                "value": incoming_document.customer
            }
        ]
    };
    var isAccepted = container.queryDocuments(container.getSelfLink(), filterQuery, {},
        function (err, items, responseOptions) {
            if (err) throw new Error("Error" + err.message);
            incoming_document.items += items.length;    
            request.setBody(incoming_document);
        }
    );

    if (!isAccepted) throw "Unable to update transaction, abort";
}
jak123
  • 318
  • 2
  • 12

1 Answers1

0
  • For getting more than 100 documents in Cosmos DB we can make use of x-ms-max-item-count.

  • The maximum number of values that can be returned by the query execution is done by the x-ms-max-item-count header.

  • The default value of the query results is 100 and it can be configured from 1–1000 using this header.

  • For more details regarding Pagination of query results in Microsoft Documentation.

  • You can Customize the number for Items per page in Query Explorer too like here.

  • 1
    Someone mentioned `maxItemCount` in a comment the other day. Note that the OP is using an SDK, not a raw REST call, so the comment under the question covers it (and there's no need to talk about headers, since this is about SDK use). Aside from that: Please don't just copy content from documentation, as an answer (it's not an answer - it's just sharing some docs). At best, you should just share the doc link as a comment under the question. – David Makogon Jun 10 '22 at 12:20