-
Notifications
You must be signed in to change notification settings - Fork 0
Filtering Example
Chris Dahlberg edited this page Mar 19, 2019
·
1 revision
To limit which source documents are included in the aggregated result, they can be filtered by calling the Where
extension method on the aggregate query.
CosmosContainer container = {{your_target_container}};
var queryOptions = new AggregateQueryOptions { PartitionKey = "13" };
var query = container.CreateAggregateDocumentQuery<Sale>(queryOptions)
.Where(x => x.StoreId == "STL314")
.Aggregate((aggregate, current) => new Sale
{
StoreId = aggregate.StoreId,
Amount = aggregate.Amount + current.Amount,
})
.AsDocumentQuery();
var results = new List<Sale>();
while (query.HasMoreResults)
{
var resultsPage = await query.ExecuteNextAsync(cancellationToken).ConfigureAwait(false);
results.AddRange(resultsPage);
}