共用方式為


Database.GetContainerQueryStreamIterator Method

Definition

Overloads

GetContainerQueryStreamIterator(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.

GetContainerQueryStreamIterator(String, String, QueryRequestOptions)

This method creates a query for containers under an database using a SQL statement. It returns a FeedIterator.

GetContainerQueryStreamIterator(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 GetContainerQueryStreamIterator (Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetContainerQueryStreamIterator : Microsoft.Azure.Cosmos.QueryDefinition * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator
Public MustOverride Function GetContainerQueryStreamIterator (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 container request.

Returns

An iterator to go through the containers

Examples

This create the stream feed iterator for containers with queryDefinition as input.

string queryText = "SELECT c.id FROM c where c.status like 'start%'";
QueryDefinition queryDefinition = new QueryDefinition(queryText);
using (FeedIterator feedIterator = this.cosmosDatabase.GetContainerQueryStreamIterator(queryDefinition))
{
    while (feedIterator.HasMoreResults)
    {
        using (ResponseMessage response = await feedIterator.ReadNextAsync())
        {
            response.EnsureSuccessStatusCode();
            using (StreamReader sr = new StreamReader(response.Content))
            using (JsonTextReader jtr = new JsonTextReader(sr))
            {
                // The stream content contains the following JSON structure
                // {"_rid":"FwsdAA==","DocumentCollections":[{"id":"container1"},{"id":"container2"}],"_count":2}
                JObject result = JObject.Load(jtr);
            }
        }
    }
}

This creates feed iterator to get a list of all the container ids

using (FeedIterator feedIterator = this.cosmosDatabase.GetContainerQueryStreamIterator(
      new QueryDefinition("select value c.id From c ")))
  {
      while (feedIterator.HasMoreResults)
      {
          using (ResponseMessage response = await feedIterator.ReadNextAsync())
          {
               response.EnsureSuccessStatusCode();
               using (StreamReader streamReader = new StreamReader(response.Content))
               using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader))
               {
                    // The stream content contains the following JSON structure
                    // {"_rid":"7p8wAA==","DocumentCollections":["container1","container2"],"_count":2}
                    JObject jObject = await JObject.LoadAsync(jsonTextReader);
                }
        }
    }
}

Remarks

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

ReadContainerStreamAsync(ContainerRequestOptions, CancellationToken) is recommended for single container look-up.

Applies to

GetContainerQueryStreamIterator(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 GetContainerQueryStreamIterator (string queryText = default, string continuationToken = default, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = default);
abstract member GetContainerQueryStreamIterator : string * string * Microsoft.Azure.Cosmos.QueryRequestOptions -> Microsoft.Azure.Cosmos.FeedIterator
Public MustOverride Function GetContainerQueryStreamIterator (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 container request.

Returns

An iterator to go through the containers

Examples

This create the stream feed iterator for containers with queryDefinition as input.

using (FeedIterator feedIterator = this.cosmosDatabase.GetContainerQueryStreamIterator(
    "SELECT c.id FROM c where c.status like 'start%'"))
{
    while (feedIterator.HasMoreResults)
    {
        using (ResponseMessage response = await feedIterator.ReadNextAsync())
        {
            response.EnsureSuccessStatusCode();
            using (StreamReader sr = new StreamReader(response.Content))
            using (JsonTextReader jtr = new JsonTextReader(sr))
            {
                // The stream content contains the following JSON structure
                // {"_rid":"FwsdAA==","DocumentCollections":[{"id":"container1"},{"id":"container2"}],"_count":2}
                JObject result = JObject.Load(jtr);
            }
        }
    }
}

This creates feed iterator to get a list of all the container ids

using (FeedIterator feedIterator = this.cosmosDatabase.GetContainerQueryStreamIterator(
      "select value c.id From c "))
  {
      while (feedIterator.HasMoreResults)
      {
          using (ResponseMessage response = await feedIterator.ReadNextAsync())
          {
               response.EnsureSuccessStatusCode();
               using (StreamReader streamReader = new StreamReader(response.Content))
               using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader))
               {
                    // The stream content contains the following JSON structure
                    // {"_rid":"7p8wAA==","DocumentCollections":["container1","container2"],"_count":2}
                    JObject jObject = await JObject.LoadAsync(jsonTextReader);
                }
        }
    }
}

Remarks

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

ReadContainerStreamAsync(ContainerRequestOptions, CancellationToken) is recommended for single container look-up.

Applies to