I have a MongoDB time series collection that stores prices information. It has following schema
{
timestamp: ISODate(),
token: String,
price: Decimal128
}
I want to fetch a list of all tokens, where will be most recent price, price 1m ago, price 5m ago e.t.c.
So for example
[{
token: "BTC”,
price: 69000,
price5M: 67000,
price10M: 65000,
price1H: 60000,
price24H: 80000},
{
token: “ETH”,
price: 3000,
…}]
I can’t wrap my head around aggregation query and where to start. There will be a lot of data, so preferably it should be efficient. Thanks!