MongoDB Charts - Cumulative document growth over time

I have an atlas cluster and I connected charts to it. I have zero experience with data visualizations (or building dashboards) and I’d like to chart the number of documents in my database over time. E.g., if in January 10 documents were created, and in February another 10 were created, then the chart should display 10 for January and 20 for February.

I know the _id field has information when the document was created, but I have no idea how to display it in the chart. So far, all I have is document count using _id in the y-axis.

What is the best way to accomplish what I’m trying to do? Is using a bar chart the best visualization to use in this situation?

Also, for some reason whenever I’m creating a chart, I get alerts saying “Query Targeting: Scanned Objects / Returned has gone above 1000”. Is there any way to stop this for happening?

Hi @Thomas_Maxwell, thanks for trying out Charts!

What you’re trying to do is actually pretty complex, so don’t feel bad that you couldn’t figure it out - but the good news is that it is possible to do what you’re after.

Basically you need to do the following:

  1. Since you want to treat the _id field as a date, you need to click the “…” button next to the _id field and choose Convert Type, then choose Date.
  2. Now make sure you have a Column chart selected
  3. Drag the _id field (which should now show as a date) onto the X axis. Keep the “Binning” toggle on and choose the binning period you want (Month is the default, and seems to be what you want).
  4. Now also drag the _id field to the Y axis. Keep the default COUNT aggregation selected. The chart should now show the number of documents created each month.
  5. Finally, enable the “Compare Periods” toggle and leave the deault “Cumulative Total” option selected.

I think this should give you what you want. My example is below.



Thank you for responding. This is exactly what I wanted.

An additional question. Is there a way to show how many documents are added daily? Maybe a text Chart Type that shows it.

I’m trying to get an average of how many documents are added daily.

You can use the exact same steps above but choose “Date of the Month” for the binning period.
Or, if you just want to know how many documents were added in the last 24 hours, you could choose a number chart, encode count(_id) in the value channel, and add a date filter to include just the last 24 hours.



This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.