Manipulating MongoDB values for a stock chart

Viewed 24

I currently have a simple line chart that is using a 'value' and 'date' to be generated. This is being pulled straight from my database (mongodb)

{
  product: 'title',
  value: 123,
  date: ISODate("2022-08-25T06:30:12.713Z")
}

I would like to now change this chart to a stock chart but instead of a 'value' and 'date' i'll need an 'open', 'close', 'high' and 'low'.

{
 product: 'title',
 open: 123,
 close: 125,
 high: 130,
 low: 120
}

What is the best and most performant way for me to approach this?

a) Mass data manipulator/processing on the front end after recieving the data from the api?

b) A huge aggregation query to calculate and group every price, for every hour that has passed since October?

c) Mass database update retrofitting and calculating all of the values and storing them as the fields I need?

d) Something else I've not considered?

Any advice greatly appreciated.

0 Answers
Related