Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Categories Database
Created by Guest
Created on Jan 9, 2023

Support compound/multiple grouping keys in $bucket

We often need to compute statistical/summarizing aggregations grouped by more than one field where all fields are of a $bucket-able type. An example, would be to count all orders grouped by their status and some custom time ranges of their creation date. This can be achieved by using $group in combination with a $switch expression (sometimes simplified with $trunc), however, that is cumbersome and prevents efficient grouping since e.g. no binary search can be employed to identify the bucket boundaries efficiently. The query syntax of $bucket would not need to change much. It would simply need to allow for nested arrays within the `boundaries` parameter whereby each nested array specifies the requested grouping range.
  • Attach files