Moving averages with MongoDB's aggregation framework?

后端 未结 5 1698
生来不讨喜
生来不讨喜 2020-12-04 01:28

If you have 50 years of temperature weather data (daily) (for example) how would you calculate moving averages, using 3-month intervals, for that time period? Can you do tha

5条回答
  •  情歌与酒
    2020-12-04 02:30

    I think I may have an answer for my own question. Map Reduce would do it. First use emit to map each document to it's neighbors that it should be averaged with, then use reduce to avg each array... and that new array of averages should be the moving averages plot overtime since it's id would be the new date interval that you care about

    I guess I needed to understand map-reduce better ...

    :)

    For instance... if we wanted to do it in memory (later we can create collections)

    GIST https://gist.github.com/mrgcohen/3f67c597a397132c46f7

    Does that look right?

提交回复
热议问题