0
votes

I'm unable to find an information about windowing operations over time series data in MongoDB Aggregation framework.

Does it support windowing operations over time series data? For example, I need to count some aggregated values based on the document timestamp each 5 minute windows and store such aggregations in separate documents for feature usage. Is it possible with MongoDB Aggregation framework to achieve this with help of MongoDB Aggregation framework pipeline and stages?

1
There is some related information as a feature request (MongoDB jira): aggregation: support windowing operation on pipelines. - prasad_

1 Answers

1
votes

You can use the following to group them in 5min windows and then run the aggregation:

db.users.aggregate([
  { "$group": {
    "_id": {
      "$toDate": {
        "$subtract": [
          { "$toLong": "$signedUp" },
          { "$mod": [ { "$toLong": "$signedUp" }, 1000 * 60 * 5 ] }
        ]
      }
    },
    "count": { "$sum": 1 }
  }}
])

The above example counts how many users signed up every 5 mins.

Example taken from here.