I am assuming that the numbers in your example aggregation represent counts
of activities (i.e. ship, order, start, and stop) that occurred in each
Year-Month combination. Please let me know if this assumption is incorrect.
Please note that this aggregation query assumes that the whole collection
will be used, which may not be very performant in a very large collection.
If your use case permits, I would recommend to add a $match stage as the
first stage (e.g. before the $project stage) to reduce the amount of data
that enters the pipeline.
If you find that you need to do this aggregation frequently, you might find
that using a Pre-Aggregated Reports
beneficial. An advantage of using pre-aggregated report is that it allows
you to generate up-to-the-minute reports without the overhead of running a
resource-intensive aggregation query, which could interfere with your
day-to-day use of the database. The reports can then be retrieved using a
single find() command. The tradeoff is that your application would need to
update two collections at once for each data point insertion (i.e. an
insert for the original collection, and another for the pre-aggregated
You received this message because you are subscribed to the Google Groups "mongodb-user"