MaxItemCount in Document DbChangeFeed

289 Views Asked by At

I am testing out the new changefeed from DocumentDb. I am connecting this to a Logic app via a polling api.

Because I only want 1 item per request, I have set the MaxItemCount to 1. This works perfectly... until a get passed 36 result. The next request, gives me 70 result (and max item count is set to 1) and +- 150 documents were skipped.

Is this a bug in DocumentDB or am I doing something wrong?

See code, the first 36 times, I only get 1 result, from then I got the issue described above:

 var changeFeedOptions = new ChangeFeedOptions
        {
            MaxItemCount = 1,
            RequestContinuation = continuationToken,
            PartitionKeyRangeId = partitionKey, // singe partioned collection
            StartFromBeginning = fromBeginning
        };

        var feed = ((DocumentClient) _documentClient).CreateDocumentChangeFeedQuery(
            collectionUri,
            changeFeedOptions);

        var result = await feed.ExecuteNextAsync();

        var document = result.FirstOrDefault();

        return new ChangeFeedResponse
        {
            ContinuationToken = result.ResponseContinuation, // this token will be used the next time
            Document = document
        };
1

There are 1 best solutions below

1
On BEST ANSWER

For Change Feed, the granularity is by transaction, which means that changes from same transaction are considered as atomic piece and it returned as such (can't break transaction). Thus result of Change Feed can extend MaxItemCount (page size) up to transaction boundary. For instance, a script inserted 70 docs -- all these come as single transaction, and you poll for changes and provide MaxItemCount = 1; what you would get is 70 items (it will stop at transaction boundary). Does this make sense?

Was that the case that these 70 docs were inserted by script?