Container.GetItemQueryStreamIterator Container.GetItemQueryStreamIterator Container.GetItemQueryStreamIterator Method

Definition

Overloads

GetItemQueryStreamIterator(String, String, QueryRequestOptions) GetItemQueryStreamIterator(String, String, QueryRequestOptions) GetItemQueryStreamIterator(String, String, QueryRequestOptions)

This method creates a query for items under a container in an Azure Cosmos 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.

GetItemQueryStreamIterator(QueryDefinition, String, QueryRequestOptions) GetItemQueryStreamIterator(QueryDefinition, String, QueryRequestOptions)

This method creates a query for items under a container in an Azure Cosmos 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.

GetItemQueryStreamIterator(String, String, QueryRequestOptions) GetItemQueryStreamIterator(String, String, QueryRequestOptions) GetItemQueryStreamIterator(String, String, QueryRequestOptions)

This method creates a query for items under a container in an Azure Cosmos 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.

public abstract Microsoft.Azure.Cosmos.FeedIterator GetItemQueryStreamIterator (string queryText = null, string continuationToken = null, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null);
abstract member GetItemQueryStreamIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator
Public MustOverride Function GetItemQueryStreamIterator (Optional queryText As String = null, Optional continuationToken As String = null, Optional requestOptions As QueryRequestOptions = null) As FeedIterator

Parameters

queryText
String String String

The cosmos SQL query text.

continuationToken
String String String

(Optional) The continuation token in the Azure Cosmos DB service.

requestOptions
QueryRequestOptions QueryRequestOptions QueryRequestOptions

(Optional) The options for the item query request QueryRequestOptions

Returns

An iterator to go through the items.

Examples

Create a query to get all the ToDoActivity that have a cost greater than 9000 for the specified partition


public class ToDoActivity{
    public string id {get; set;}
    public string status {get; set;}
    public int cost {get; set;}
}

FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator(
    queryText: "select * from ToDos t where t.cost > 9000", 
    requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Error")});
    
while (feedIterator.HasMoreResults)
{
    using (CosmosResponseMessage response = await feedIterator.FetchNextSetAsync())
    {
        using (StreamReader sr = new StreamReader(response.Content))
        using (JsonTextReader jtr = new JsonTextReader(sr))
        {
            JObject result = JObject.Load(jtr);
        }
    }
}
  1. Create a query to get all the ToDoActivity that have a cost greater than 9000 for the specified partition

 public class ToDoActivity{
     public string id {get; set;}
     public string status {get; set;}
     public int cost {get; set;}
 }
 
 FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator(
     "select * from ToDos t where t.cost > 9000",
     null,
     new QueryRequestOptions() { PartitionKey = new PartitionKey("Error")});

 while (feedIterator.HasMoreResults)
 {
     using (ResponseMessage response = await feedIterator.ReadNextAsync())
     {
         using (StreamReader sr = new StreamReader(response.Content))
         using (JsonTextReader jtr = new JsonTextReader(sr))
         {
             JObject result = JObject.Load(jtr);
         }
     }
 }
 
  1. Creates a FeedIterator to get all the ToDoActivity.

 public class ToDoActivity{
     public string id {get; set;}
     public string status {get; set;}
     public int cost {get; set;}
 }

 FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator(
     null,
     null,
     new QueryRequestOptions() { PartitionKey = new PartitionKey("Error")});

 while (feedIterator.HasMoreResults)
 {
     using (ResponseMessage response = await feedIterator.ReadNextAsync())
     {
         using (StreamReader sr = new StreamReader(response.Content))
         using (JsonTextReader jtr = new JsonTextReader(sr))
         {
             JObject result = JObject.Load(jtr);
         }
     }
 }
 

Remarks

Query as a stream only supports single partition queries

GetItemQueryStreamIterator(QueryDefinition, String, QueryRequestOptions) GetItemQueryStreamIterator(QueryDefinition, String, QueryRequestOptions)

This method creates a query for items under a container in an Azure Cosmos 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.

public abstract Microsoft.Azure.Cosmos.FeedIterator GetItemQueryStreamIterator (Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = null, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null);
abstract member GetItemQueryStreamIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator

Parameters

queryDefinition
QueryDefinition QueryDefinition QueryDefinition

The cosmos SQL query definition.

continuationToken
String String String

(Optional) The continuation token in the Azure Cosmos DB service.

requestOptions
QueryRequestOptions QueryRequestOptions QueryRequestOptions

(Optional) The options for the item query request QueryRequestOptions

Returns

An iterator to go through the items.

Examples

Create a query to get all the ToDoActivity that have a cost greater than 9000 for the specified partition


public class ToDoActivity{
    public string id {get; set;}
    public string status {get; set;}
    public int cost {get; set;}
}

QueryDefinition queryDefinition = new QueryDefinition("select * from ToDos t where t.cost > @expensive").WithParameter("@expensive", 9000);
FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator(
    queryDefinition: queryDefinition, 
    requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Error")});
    
while (feedIterator.HasMoreResults)
{
    using (CosmosResponseMessage response = await feedIterator.FetchNextSetAsync())
    {
        using (StreamReader sr = new StreamReader(response.Content))
        using (JsonTextReader jtr = new JsonTextReader(sr))
        {
            JObject result = JObject.Load(jtr);
        }
    }
}

Create a query to get all the ToDoActivity that have a cost greater than 9000 for the specified partition


 public class ToDoActivity{
     public string id {get; set;}
     public string status {get; set;}
     public int cost {get; set;}
 }
 
 QueryDefinition queryDefinition = new QueryDefinition("select * from ToDos t where t.cost > @expensive")
     .WithParameter("@expensive", 9000);
 FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator(
     queryDefinition,
     null,
     new QueryRequestOptions() { PartitionKey = new PartitionKey("Error")});

 while (feedIterator.HasMoreResults)
 {
     using (ResponseMessage response = await feedIterator.ReadNextAsync())
     {
         using (StreamReader sr = new StreamReader(response.Content))
         using (JsonTextReader jtr = new JsonTextReader(sr))
         {
             JObject result = JObject.Load(jtr);
         }
     }
 }
 

Remarks

Query as a stream only supports single partition queries

Applies to