my project is based on Hapi.js and Mongoose. I'm stuck in getting the X prices from 24h ago.
I'm getting the latest added record in this way:
const pricesnow = await Prices.find({
currency_id: {
$in:
currencies[k].id
},
createdAt: {
$gt: new Date().getTime() - 1000 * 60 * 1
}
})
So I thought that I can get the x records from 24h ago with this code:
const prices24h = await Prices.find({
currency_id: {
$in:
currencies[k].id
},
createdAt: {
$gt: new Date().getTime() - 86400000,
$lt: new Date().getTime() - 86399999
}
})
But even there is data in the database, the prices from 24 hours ago doesnt return.
The second code only works if the time span is within an hour.
After that I'm going to subtract prices24h from pricesnow to calculate the 24h percentage.
Thanks in advance for your answers.