CosmosItems.CreateItemQueryAsStream CosmosItems.CreateItemQueryAsStream CosmosItems.CreateItemQueryAsStream Method

Definition

Overloads

CreateItemQueryAsStream(CosmosSqlQueryDefinition, Object, Nullable<Int32>, String, CosmosQueryRequestOptions) CreateItemQueryAsStream(CosmosSqlQueryDefinition, Object, Nullable<Int32>, String, CosmosQueryRequestOptions) CreateItemQueryAsStream(CosmosSqlQueryDefinition, Object, Nullable<Int32>, String, CosmosQueryRequestOptions)

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 CosmosResultSetStreamIterator. For more information on preparing SQL statements with parameterized values, please see CosmosSqlQueryDefinition.

CreateItemQueryAsStream(String, Object, Nullable<Int32>, String, CosmosQueryRequestOptions) CreateItemQueryAsStream(String, Object, Nullable<Int32>, String, CosmosQueryRequestOptions) CreateItemQueryAsStream(String, Object, Nullable<Int32>, String, CosmosQueryRequestOptions)

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 CosmosResultSetStreamIterator. For more information on preparing SQL statements with parameterized values, please see CosmosSqlQueryDefinition.

CreateItemQueryAsStream(CosmosSqlQueryDefinition, Object, Nullable<Int32>, String, CosmosQueryRequestOptions) CreateItemQueryAsStream(CosmosSqlQueryDefinition, Object, Nullable<Int32>, String, CosmosQueryRequestOptions) CreateItemQueryAsStream(CosmosSqlQueryDefinition, Object, Nullable<Int32>, String, CosmosQueryRequestOptions)

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 CosmosResultSetStreamIterator. For more information on preparing SQL statements with parameterized values, please see CosmosSqlQueryDefinition.

public virtual Microsoft.Azure.Cosmos.CosmosResultSetIterator CreateItemQueryAsStream (Microsoft.Azure.Cosmos.CosmosSqlQueryDefinition sqlQueryDefinition, object partitionKey, Nullable<int> maxItemCount = null, string continuationToken = null, Microsoft.Azure.Cosmos.CosmosQueryRequestOptions requestOptions = null);
abstract member CreateItemQueryAsStream : Microsoft.Azure.Cosmos.CosmosSqlQueryDefinition * obj * Nullable<int> * string * Microsoft.Azure.Cosmos.CosmosQueryRequestOptions -> Microsoft.Azure.Cosmos.CosmosResultSetIterator
override this.CreateItemQueryAsStream : Microsoft.Azure.Cosmos.CosmosSqlQueryDefinition * obj * Nullable<int> * string * Microsoft.Azure.Cosmos.CosmosQueryRequestOptions -> Microsoft.Azure.Cosmos.CosmosResultSetIterator
Public Overridable Function CreateItemQueryAsStream (sqlQueryDefinition As CosmosSqlQueryDefinition, partitionKey As Object, Optional maxItemCount As Nullable(Of Integer) = null, Optional continuationToken As String = null, Optional requestOptions As CosmosQueryRequestOptions = null) As CosmosResultSetIterator

Parameters

sqlQueryDefinition
CosmosSqlQueryDefinition CosmosSqlQueryDefinition CosmosSqlQueryDefinition

The cosmos SQL query definition.

partitionKey
Object Object Object

The partition key for the item. Microsoft.Azure.Cosmos.PartitionKey

maxItemCount
Nullable<Int32>

(Optional) The max item count to return as part of the query

continuationToken
String String String

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

requestOptions
CosmosQueryRequestOptions CosmosQueryRequestOptions CosmosQueryRequestOptions

(Optional) The options for the item query request CosmosQueryRequestOptions

Returns

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;}
}

CosmosSqlQueryDefinition sqlQuery = new CosmosSqlQueryDefinition("select * from ToDos t where t.cost > @expensive").UseParameter("@expensive", 9000);
CosmosResultSetIterator setIterator = this.Container.Items.CreateItemQueryAsStream(
    sqlQueryDefinition: sqlQuery, 
    partitionKey: "Error");
    
while (setIterator.HasMoreResults)
{
    using (CosmosResponseMessage response = await setIterator.FetchNextSetAsync())
    {
        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

CreateItemQueryAsStream(String, Object, Nullable<Int32>, String, CosmosQueryRequestOptions) CreateItemQueryAsStream(String, Object, Nullable<Int32>, String, CosmosQueryRequestOptions) CreateItemQueryAsStream(String, Object, Nullable<Int32>, String, CosmosQueryRequestOptions)

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 CosmosResultSetStreamIterator. For more information on preparing SQL statements with parameterized values, please see CosmosSqlQueryDefinition.

public virtual Microsoft.Azure.Cosmos.CosmosResultSetIterator CreateItemQueryAsStream (string sqlQueryText, object partitionKey, Nullable<int> maxItemCount = null, string continuationToken = null, Microsoft.Azure.Cosmos.CosmosQueryRequestOptions requestOptions = null);
abstract member CreateItemQueryAsStream : string * obj * Nullable<int> * string * Microsoft.Azure.Cosmos.CosmosQueryRequestOptions -> Microsoft.Azure.Cosmos.CosmosResultSetIterator
override this.CreateItemQueryAsStream : string * obj * Nullable<int> * string * Microsoft.Azure.Cosmos.CosmosQueryRequestOptions -> Microsoft.Azure.Cosmos.CosmosResultSetIterator
Public Overridable Function CreateItemQueryAsStream (sqlQueryText As String, partitionKey As Object, Optional maxItemCount As Nullable(Of Integer) = null, Optional continuationToken As String = null, Optional requestOptions As CosmosQueryRequestOptions = null) As CosmosResultSetIterator

Parameters

sqlQueryText
String String String

The cosmos SQL query string.

partitionKey
Object Object Object

The partition key for the item. Microsoft.Azure.Cosmos.PartitionKey

maxItemCount
Nullable<Int32>

(Optional) The max item count to return as part of the query

continuationToken
String String String

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

requestOptions
CosmosQueryRequestOptions CosmosQueryRequestOptions CosmosQueryRequestOptions

(Optional) The options for the item query request CosmosQueryRequestOptions

Returns

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;}
}

CosmosResultSetIterator setIterator = this.Container.Items.CreateItemQueryAsStream(
    sqlQueryText: "select * from ToDos t where t.cost > 9000", 
    partitionKey: "Error");
    
while (setIterator.HasMoreResults)
{
    using (CosmosResponseMessage response = await setIterator.FetchNextSetAsync())
    {
        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