Does Azure Cosmos DB support - Mongo API aggregation

I was looking to use cosmosdb to store time-series data set forth in a document-oriented design . Using the official mongodb driver, I tried to write some simple aggregation operators; however, I got errors stating that $ unwind and $ group are not supported. Given that cosmosdb was advertised as a replacement for replacing mongodb, I skipped a step or aggregation is not supported.

retrieve.Aggregate().Unwind(i => i.Observations).Group(new BsonDocument { {"_id", "$Observations.Success"}, {"avg", new BsonDocument{ {"$avg", "$Observations.Duration"} }} }).ToList(); 
+7
c # mongodb mongodb-.net-driver azure-cosmosdb
source share
2 answers

As of November 2017, the Cosmos DB MongoDB API now supports an aggregation pipeline, including all pipeline stages defined in your original question ( $unwind , $group ).

Features of the supported features are listed here .

+2
source share

Given the comment from @neillunn and the lack of any documentation for this effect, it seems that the aggregation functions for cosmosdb are not supported through the mongo API. It seems like the intention is to use the cosmosdb Documentdb API SQL syntax for aggregates.

LINQ Syntax

 var client = new DocumentClient(new Uri("https://<account>.documents.azure.com"),<password>); // issue query var documentUri = UriFactory.CreateDocumentCollectionUri("Prod", "retrieve"); var date = "20161011".Dump("Date"); var max = client.CreateDocumentQuery<ObservationDocument>(documentUri) .Where(i => i.Id == date) .SelectMany(i => i.observations) .Max(i => i.Duration); 

SQL syntax

 // explicit query var spec = new SqlQuerySpec("select value count(o.duration) from days d join o in d.observations where d._id = @id"); spec.Parameters = new Microsoft.Azure.Documents.SqlParameterCollection(); spec.Parameters.Add(new Microsoft.Azure.Documents.SqlParameter("@id", "20161010")); client.CreateDocumentQuery(UriFactory.CreateDocumentCollectionUri("Prod", "retrieve"), spec).Dump("As query"); 
+7
source share