These are chat archives for Automattic/mongoose

Jul 2017
Dennis Belany
Jul 12 2017 03:05
could someone help me with a complicated mongo query? I have an aggergate query that selects data from a time range and returns a time series, i would like to average the results and just get only one number. And i would like to compare it against an another query which is again returns with a time series data, and what i would need is to adjust the time range for every array item the second query returns.
And its quite performance slow to repeat the same query with different time range
Paul "Joey" Clark
Jul 12 2017 08:04
@azarus For averaging, something like this might work: {$group: {_id: null, average: {$avg: ‘$fieldName’}}} $avg
Paul "Joey" Clark
Jul 12 2017 08:14

For different time periods, the easy way is to just let Mongo do the work.
But if your time periods are granular to the hour, you could group/split the data according to hour:

_id: {year: {$year: “$dateField”}, month: {$month: “$dateField”}, day: {$dayOfMonth: “$dateField”}, hour: {$hour: “$dateField”}}

Then in Javascript you could add up the sums for each hour, to get the total for any given time period (to the nearest hour). Date Aggregation Operations

Dennis Belany
Jul 12 2017 12:28
@pablovilas i need to get the data for a dataset that has a timestamp and an averaged value already. And i would like to get the average from a second document based on that timestamp.
I know how to use $avg my issue is that if i habe long timeseries datasets it gets slow since i see no other way around than doing an another query and repeating the query for every point
Also my time series data could come from other sources not only from a mongo
I am looking for a way to group by based on an array
Jul 12 2017 19:39
Hi; I've got something like an Exercise model with some light fields like date, author etc but there is also a huge, and I mean really huge image: Buffer. How should I serve it without wasting tremendous amount of RAM?