Database.GetContainerQueryIterator Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
GetContainerQueryIterator<T>(QueryDefinition, String, QueryRequestOptions) |
This method creates a query for containers under an database using a SQL statement with parameterized values. It returns a FeedIterator. For more information on preparing SQL statements with parameterized values, please see QueryDefinition overload. |
GetContainerQueryIterator<T>(String, String, QueryRequestOptions) |
This method creates a query for containers under an database using a SQL statement. It returns a FeedIterator. |
GetContainerQueryIterator<T>(QueryDefinition, String, QueryRequestOptions)
- Source:
- Database.cs
This method creates a query for containers under an database using a SQL statement with parameterized values. It returns a FeedIterator. For more information on preparing SQL statements with parameterized values, please see QueryDefinition overload.
public abstract Microsoft.Azure.Cosmos.FeedIterator<T> GetContainerQueryIterator<T> (Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetContainerQueryIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public MustOverride Function GetContainerQueryIterator(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
(Optional) 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 containers
Examples
This create the type feed iterator for containers with queryDefinition as input.
QueryDefinition queryDefinition = new QueryDefinition("SELECT * FROM c where c.status like @status");
.WithParameter("@status", "start%");
using (FeedIterator<ContainerProperties> feedIterator = this.cosmosDatabase.GetContainerQueryIterator<ContainerProperties>(queryDefinition))
{
while (feedIterator.HasMoreResults)
{
FeedResponse<ContainerProperties> response = await feedIterator.ReadNextAsync();
foreach (var container in response)
{
Console.WriteLine(container);
}
}
}
Remarks
Refer to https://docs.microsoft.com/azure/cosmos-db/sql-query-getting-started for syntax and examples.
ReadContainerAsync(ContainerRequestOptions, CancellationToken) is recommended for single container look-up.
Applies to
GetContainerQueryIterator<T>(String, String, QueryRequestOptions)
- Source:
- Database.cs
This method creates a query for containers under an database using a SQL statement. It returns a FeedIterator.
public abstract Microsoft.Azure.Cosmos.FeedIterator<T> GetContainerQueryIterator<T> (string queryText = default, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetContainerQueryIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator<'T>
Public MustOverride Function GetContainerQueryIterator(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
(Optional) 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 containers
Examples
- This create the type feed iterator for containers with queryText as input,
string queryText = "SELECT * FROM c where c.status like 'start%'";
using (FeedIterator<ContainerProperties> feedIterator = this.cosmosDatabase.GetContainerQueryIterator<ContainerProperties>(queryText))
{
while (feedIterator.HasMoreResults)
{
FeedResponse<ContainerProperties> response = await feedIterator.ReadNextAsync();
foreach (var container in response)
{
Console.WriteLine(container);
}
}
}
- This create the type feed iterator for containers without queryText, retrieving all containers.
using (FeedIterator<ContainerProperties> feedIterator = this.cosmosDatabase.GetContainerQueryIterator<ContainerProperties>())
{
while (feedIterator.HasMoreResults)
{
FeedResponse<ContainerProperties> response = await feedIterator.ReadNextAsync();
foreach (var container in response)
{
Console.WriteLine(container);
}
}
}
Remarks
Refer to https://docs.microsoft.com/azure/cosmos-db/sql-query-getting-started for syntax and examples.
ReadContainerAsync(ContainerRequestOptions, CancellationToken) is recommended for single container look-up.
Applies to
Azure SDK for .NET