In my mongodb there is measured_data (measured_at, value) saved a couple times for each day.
Does anybody know how to find the lowest value for each day with mongoose?
Thanks!
In my mongodb there is measured_data (measured_at, value) saved a couple times for each
Share
There isn’t really a great way to do this in mongodb that I know of, you’ll have to do this on the client side. Basically grab all the values, sort, and take lowest one.
If performance is a concern, just create a new property called min_measured_data on your mongoose model. You can then hook pre ‘save’ using mongoose and compare any new measured data to the min. If it’s less than the min, update min_measured_data accordingly. This way, anytime you need to read this property it will be O(1) instead of having to redo the sort everytime.