[SERVER-37136] $bucketInterval for grouping data in intervaled buckets (eg. time series) Created: 14/Sep/18  Updated: 27/Dec/23

Status: Backlog
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Daniel Faust Assignee: Backlog - Query Integration
Resolution: Unresolved Votes: 0
Labels: qi-timeseries
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Integration
Participants:

 Description   

The following StackOverflow question and answer raises the issue and provides a solution for this feature.

Resample Time Series Data using Javascript and Mongodb

 

In addition of creating a bucket with predefined boundaries ($bucket), or one with autogenerated boundaries ($bucketAuto), it would be helpful to have a bucket stage which is given an upper and lower boundary, and the buckets are generated automatically at fixed, predefined intervals, for example

 

{{{}}
  $bucketInterval: {
    groupBy: '$timestamp',
    }}{{lower: ISODate("2014-10-23T00:00:00.000+02:00"),
    }}{{upper: ISODate("2014-10-24T00:00:00.000+02:00"),
    }}{{interval: 5*60*1000,
    }}{{output: {
      total:    {$sum: 1},
      incoming: {$sum: "$i"},
      outgoing: {$sum: "$o"},
    }}{
{{  }}}
}

 

 



 Comments   
Comment by David Storch [ 21/Sep/18 ]

One nice way to achieve this might be to allow the existing $bucket stage to accept an expression, and expressing the boundaries with $range.

Comment by Daniel Faust [ 18/Sep/18 ]

And maybe also an `inclusiveUpper: true|false`, maybe also add `inclusiveLower : true|false`

For example, if `lower = 0`, `upper = 17` and `interval = 5`, then

  • ASC – would result in [0-5),[5-10),[10-15),[15-17*]* (17 included in last bucket) and
  • DESC – in [0,2),[2,7),[7,12),[12,17*]*
Comment by Daniel Faust [ 18/Sep/18 ]

Also a growth direction would be useful. `growth: ASC|DESC`.

For example, if `lower = 0`, `upper = 17` and `interval = 5`, then

  • ASC – would result in [0-5),[5-10),[10-15),[15-17) and
  • DESC – in [0,2),[2,7),[7,12),[12,17)  (starts at 17 and goes down) ( or (0,2],(2,7],(7,12],(12,17] ? )
Comment by Nick Brewer [ 14/Sep/18 ]

danielfaust Thanks for your request - I've passed this along to our Query team for consideration.

-Nick

Generated at Thu Feb 08 04:45:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.