The number of document to copy is calculated in CosmosDBHelper.GetSourceRecordCount in an invalid way.
The code below
sourceTotalRecordCount = cosmosClient.CreateDocumentQuery<long>(
UriFactory.CreateDocumentCollectionUri(sourceDatabaseName, sourceCollectionName), totalCountQuery, queryOptions)
.AsEnumerable().First();
uses First() to obtain only the first page of the results, and assumes that this is the total number of documents.
In fact, for larger collections, Cosmos DB will return multiple pages with partial counts, which have to be summed up in order to obtain the true total.
The correct code should enumerate all pages in the response.
The number of document to copy is calculated in
CosmosDBHelper.GetSourceRecordCountin an invalid way.The code below
uses
First()to obtain only the first page of the results, and assumes that this is the total number of documents.In fact, for larger collections, Cosmos DB will return multiple pages with partial counts, which have to be summed up in order to obtain the true total.
The correct code should enumerate all pages in the response.