Share via


CosmosClient.GetDatabaseQueryIterator Method

Definition

Overloads

GetDatabaseQueryIterator<T>(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.

GetDatabaseQueryIterator<T>(String, String, QueryRequestOptions)

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

GetDatabaseQueryIterator<T>(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<T> GetDatabaseQueryIterator<T> (Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetDatabaseQueryIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
override this.GetDatabaseQueryIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public Overridable Function GetDatabaseQueryIterator(Of T) (queryDefinition As QueryDefinition, Optional continuationToken As String = Nothing, Optional requestOptions As QueryRequestOptions = Nothing) As FeedIterator(Of T)

Type Parameters

T

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 item query request.

Returns

An iterator to go through the databases.

Examples

This create the type feed iterator for database with queryText as input,

QueryDefinition queryDefinition = new QueryDefinition("SELECT * FROM c where c.status like @status")
    .WithParameter("@status", "start%");
using (FeedIterator<DatabaseProperties> feedIterator = this.users.GetDatabaseQueryIterator<DatabaseProperties>(queryDefinition))
{
    while (feedIterator.HasMoreResults)
    {
        FeedResponse<DatabaseProperties> response = await feedIterator.ReadNextAsync();
        foreach (var database in response)
        {
            Console.WriteLine(database);
        }
    }
}

Remarks

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

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

Applies to

GetDatabaseQueryIterator<T>(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<T> GetDatabaseQueryIterator<T> (string queryText = default, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetDatabaseQueryIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
override this.GetDatabaseQueryIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public Overridable Function GetDatabaseQueryIterator(Of T) (Optional queryText As String = Nothing, Optional continuationToken As String = Nothing, Optional requestOptions As QueryRequestOptions = Nothing) As FeedIterator(Of T)

Type Parameters

T

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 item query request.

Returns

An iterator to go through the databases.

Examples

This create the type feed iterator for database with queryText as input,

string queryText = "SELECT * FROM c where c.status like 'start%'";
using (FeedIterator<DatabaseProperties> feedIterator = this.users.GetDatabaseQueryIterator<DatabaseProperties>(queryText)
{
    while (feedIterator.HasMoreResults)
    {
        FeedResponse<DatabaseProperties> response = await feedIterator.ReadNextAsync();
        foreach (var database in response)
        {
            Console.WriteLine(database);
        }
    }
}

Remarks

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

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

Applies to