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
- README.md
- source code documentation
- SDK API docs on https://docs.microsoft.com
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:
- Insert a bunch of records into a container, with different partition keys.
- 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.)
- Try Step 2 for all documents in the container, until one fails to be returned by the first call to fetchNext()
- 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.
Metadata
Assignees
Labels
Type
Projects
Status
Done