Skip to content

fetchNext() does not return the first result #23771

Closed as not planned
Closed as not planned

Description

  • Package Name: @azure/cosmos
  • Package Version: 3.17.1
  • Operating system: MacOS and Azure App Services
  • nodejs
    • version: 14 and 16
  • browser
    • name/version:
  • typescript
    • version: 4.8.4
  • Is the bug related to documentation in

Describe the bug
After investigation we found that there is as any issue with the fetchNext() method that we are using, when we only expect one database result.

Sometimes the first call to fetchNext() will return an empty array of resources with hasMoreResults = true. In order to get the first record in this situation you have to call fetchNext() multiple times until you get a result, or hasMoreResults becomes comes false.

On the other hand fetchAll() will call fetchNext() multiple times until all the results are retrieved. (There are no more results.)

So we are switching all of the findOne() and similar methods over to use fetchAll() to avoid this problem.

To Reproduce
Steps to reproduce the behavior:

  1. Insert a bunch of records into a container, with different partition keys.
  2. Try to query for a single document with a unique identifier that is not the id/pk of the container. (This means that the queries will be cross partition queries.)
  3. Try Step 2 for all documents in the container, until one fails to be returned by the first call to fetchNext()
  4. This behavior will repeatable for the document identified in Step 3

Expected behavior
The first call to fetchNext() always returns the first query result.

Actual behavior
The first call to fetchNext() does not always return the first result.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

ClientThis issue points to a problem in the data-plane of the library.CosmosService AttentionWorkflow: This issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions