Share via


CosmosClient.GetDatabaseQueryStreamIterator Method

Definition

Overloads

GetDatabaseQueryStreamIterator(QueryDefinition, String, QueryRequestOptions)

This method creates a query for databases under an Cosmos DB Account using a SQL statement with parameterized values. It returns a FeedIterator. For more information on preparing SQL statements with parameterized values, please see QueryDefinition.

GetDatabaseQueryStreamIterator(String, String, QueryRequestOptions)

This method creates a query for databases under an Cosmos DB Account using a SQL statement. It returns a FeedIterator.

GetDatabaseQueryStreamIterator(QueryDefinition, String, QueryRequestOptions)

Source:
CosmosClient.cs

This method creates a query for databases under an Cosmos DB Account using a SQL statement with parameterized values. It returns a FeedIterator. For more information on preparing SQL statements with parameterized values, please see QueryDefinition.

public virtual Microsoft.Azure.Cosmos.FeedIterator GetDatabaseQueryStreamIterator (Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetDatabaseQueryStreamIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator
override this.GetDatabaseQueryStreamIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator
Public Overridable Function GetDatabaseQueryStreamIterator (queryDefinition As QueryDefinition, Optional continuationToken As String = Nothing, Optional requestOptions As QueryRequestOptions = Nothing) As FeedIterator

Parameters

queryDefinition
QueryDefinition

The cosmos SQL query definition.

continuationToken
String

The continuation token in the Azure Cosmos DB service.

requestOptions
QueryRequestOptions

(Optional) The options for the query request.

Returns

An iterator to go through the databases

Examples

Example on how to fully drain the query results.

QueryDefinition queryDefinition = new QueryDefinition("select * From c where c._rid = @rid")
              .WithParameter("@rid", "TheRidValue");
using (FeedIterator feedIterator = this.CosmosClient.GetDatabaseQueryStreamIterator(
    queryDefinition)
{
    while (feedIterator.HasMoreResults)
    {
        // Stream iterator returns a response with status for errors
        using(ResponseMessage response = await feedIterator.ReadNextAsync())
        {
            // Handle failure scenario. 
            if(!response.IsSuccessStatusCode)
            {
                // Log the response.Diagnostics and handle the error
            }
        }
    }
}

Remarks

Refer to https://docs.microsoft.com/azure/cosmos-db/sql-query-getting-started for syntax and examples.

ReadStreamAsync(RequestOptions, CancellationToken) is recommended for single database look-up.

Applies to

GetDatabaseQueryStreamIterator(String, String, QueryRequestOptions)

Source:
CosmosClient.cs

This method creates a query for databases under an Cosmos DB Account using a SQL statement. It returns a FeedIterator.

public virtual Microsoft.Azure.Cosmos.FeedIterator GetDatabaseQueryStreamIterator (string queryText = default, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetDatabaseQueryStreamIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator
override this.GetDatabaseQueryStreamIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator
Public Overridable Function GetDatabaseQueryStreamIterator (Optional queryText As String = Nothing, Optional continuationToken As String = Nothing, Optional requestOptions As QueryRequestOptions = Nothing) As FeedIterator

Parameters

queryText
String

The cosmos SQL query text.

continuationToken
String

The continuation token in the Azure Cosmos DB service.

requestOptions
QueryRequestOptions

(Optional) The options for the query request.

Returns

An iterator to go through the databases

Examples

Example on how to fully drain the query results.

using (FeedIterator feedIterator = this.CosmosClient.GetDatabaseQueryStreamIterator(
    ("select * From c where c._rid = 'TheRidValue'")
{
    while (feedIterator.HasMoreResults)
    {
        // Stream iterator returns a response with status for errors
        using(ResponseMessage response = await feedIterator.ReadNextAsync())
        {
            // Handle failure scenario. 
            if(!response.IsSuccessStatusCode)
            {
                // Log the response.Diagnostics and handle the error
            }
        }
    }
}

Remarks

Refer to https://docs.microsoft.com/azure/cosmos-db/sql-query-getting-started for syntax and examples.

ReadStreamAsync(RequestOptions, CancellationToken) is recommended for single database look-up.

Applies to