Here is a document in my collection in mongodb 4.4.12(could not use latest 5.0.6 because of the Intel AVX support required by mongodb 5.0.0 and above
I really want to use the native mongodb time series but for now i can’t
Now i got the context out of the way
Now back to the document, here it is
{
_id: ObjectId('61fbeb4e41691f4d9f012434'),
time_stamp: ISODate('2022-02-03T14:48:11.000Z'),
trading_pair: '1INCH-BTC',
price: 0.0000439,
status: 'online',
trading_disabled: false
}
and these documents get inserted every 1 minute, sometimes a minute is skipped and 2 minute range before next insert, even though i run the cronjob every 1 minute, but many factors that does not allow every minute always
{
_id: ObjectId('61fbeb4e41691f4d9f012432'),
time_stamp: ISODate('2022-02-03T14:45:11.000Z'),
trading_pair: '1INCH-BTC',
price: 0.0000437,
status: 'online',
trading_disabled: false
},
{
_id: ObjectId('61fbeb4e41691f4d9f012433'),
time_stamp: ISODate('2022-02-03T14:47:11.000Z'),
trading_pair: '1INCH-BTC',
price: 0.0000438,
status: 'online',
trading_disabled: false
},
{
_id: ObjectId('61fbeb4e41691f4d9f012434'),
time_stamp: ISODate('2022-02-03T14:48:11.000Z'),
trading_pair: '1INCH-BTC',
price: 0.0000439,
status: 'online',
trading_disabled: false
},
Please note i insert many documents all at once using same exact ISODate, so i can have like 100 documents all using same ISODate with different and unique values for trading_pair
…which is why i want to query by date.
Eventually i will move over to using the native timeseries MongoDB's New Time Series Collections | MongoDB
What i want to do is be able to
-
I want to be able to return only the most recent single document when i search. So it will return all documents from the most recent
InsertMany
…so i can always get the most recent price data for alltrading_pair
-
How do i perform
percentage change
to calculate percentage price difference for atrading_pair
between different ISODate for like last5 minutes
,24 hours
,7 days
? This part is the one i really want to see how to do. I am new to MongoDB , in the sense i haven’t used in PRODUCTION app before but now it is that time to fo it, and i want to do it right(need your help here)