Does the cosmos GetItemQueryIterator method throw exception if it couldn't find any records?

Venkata Sridhar Perepu 20 Reputation points Microsoft Vendor
2025-02-11T23:08:32.9933333+00:00

Can you help me understand the GetItemQueryIterator<> method in Cosmos DB? Specifically, does it throw an exception if no records are found in the database? Additionally, does it query and return results partition by partition?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,753 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sai Raghunadh M 2,485 Reputation points Microsoft Vendor
    2025-02-12T00:24:36.01+00:00

    Hi @Venkata Sridhar Perepu

    Thanks for the Question and using Microsoft Q&A.

    Can you help me understand the GetItemQueryIterator<> method in Cosmos DB?

    The GetItemQueryIterator<T> method in Cosmos DB is used to create a query for items in a container using a SQL statement. It returns a FeedIterator<T> that can be used to iterate through the results.

    does it throw an exception if no records are found in the databaseT

    The GetItemQueryIterator<T> method does not throw an exception if no records are found. Instead, it returns an empty result set. You can check if there are more results by using the HasMoreResults property of the FeedIterator<T>.

    does it query and return results partition by partition?

    Yes, the method can query and return results partition by partition. If you specify a partition key in your query, Cosmos DB will optimize the query to target only the relevant partitions. If no partition key is specified, the query will fan out to all physical partitions.

    Please go through these Documentations that might help you:

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.container.getitemqueryiterator?view=azure-dotnet

    https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-query-container

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.