Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid method of counting documents #11

Open
jkonecki opened this issue Sep 1, 2019 · 0 comments
Open

Invalid method of counting documents #11

jkonecki opened this issue Sep 1, 2019 · 0 comments

Comments

@jkonecki
Copy link
Contributor

jkonecki commented Sep 1, 2019

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.

sacheinbaala added a commit to sacheinbaala/CosmicClone that referenced this issue Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant