Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to group by for cosmos db

Given that cosmos db does not support group by, what is a good alternative to achieve similar functionality:

Select sum(*) , groupterm from tble group by groupterm

Can I efficiently achieve this in a cosmos stored procedure?

like image 362
Slicc Avatar asked Jul 23 '17 21:07

Slicc


People also ask

Does Cosmos DB have a schema?

Despite being schema-agnostic, it's worth thinking about modelling your Cosmos DB data to ensure high-performance and scalability. Azure Cosmos DB is schema-agnostic by nature, which is great if we are working with unstructured or semi-structured data within our applications.

Which API is best for Cosmos DB?

API for Apache Cassandra Apache Cassandra offers a highly distributed, horizontally scaling approach to storing large volumes of data while offering a flexible approach to a column-oriented schema. API for Cassandra in Azure Cosmos DB aligns with this philosophy to approaching distributed NoSQL databases.

Can I use Mongoose with Cosmos DB?

Azure Cosmos DB for MongoDB is compatible with up to version 5.13. 15 of Mongoose.

Why MongoDB is better than Cosmos DB?

Cosmos DB also does not support time-series data. MongoDB, on the other hand, lets you run key-value, graph, and SQL queries against the same data. And, with MongoDB 5.0, you can build and run applications with support for specific time-series data storage and query patterns.


1 Answers

As Cosmos_DB states as follows:

Aggregation capability in SQL limited to COUNT, SUM, MIN, MAX, AVG functions. No support for GROUP BY or other aggregation functionality found in database systems. However, stored procedures can be used to implement in-the-database aggregation capability.

Can I efficiently achieve this in a cosmos stored procedure?

For .NET and Node.js

Larry Maccherone has provided a great package documentdb-lumenize which supports Aggregations (Group-by, Pivot-table, and N-dimensional Cube) and Time Series Transformations as Stored Procedures in DocumentDB.

Additionally, for Python and Scala, you could refer to azure-cosmosdb-spark.

like image 127
Bruce Chen Avatar answered Sep 27 '22 21:09

Bruce Chen