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 Charts
Created by Guest
Created on Dec 18, 2019

Custom Binning Ranges

Hi Tom (and Team). We would love the ability to bin by custom ranges. We currently can only set a static number, which can lead to some pretty non-standard groupings of data. EG: For Age, we'd like to be able to create the following bins: 0-17, 18-25, 26-35, 36-45, etc... Since under 18 is a common age range to group together, the bins we have to used are 0-17, 18-34, 35-52, etc..., which isn't a terribly standard age range to group data by.
  • Guest
    Dec 19, 2019
    Hi Brian - That's a good idea. We will be looking at enhancing binning next year so I'll see if we can do something along those lines. In the meantime, it is possible to achieve what you're looking for with a calculated field. For example you could create a field with a definition like this: { $switch: { branches: [ { case: { $lt: [ '$age, 18 ] }, then: "0-18" }, { case: { $lt: [ '$age', 30 ] }, then: "18-30" }, ], default: "30+" } } One thing to consider is that the resulting labels will be strings, so you'll need to choose names that put them in the right order with an alphabetical sort.