I have this values on my MongoDB:
I need to group them by date and by the value. I need to create a chart that shows when the value changed. And I need to show only if the value changed.
How can I do it in MongoDb?
My currently aggregation is like this:
let history = await History.aggregate([
{
$match: {
address: "123456",
token_to_index: "1"
}
},
{
$group: {
_id : {
date: "$date",
floor_price: "$stats.floor_price"
},
count: { $sum: 1 }
}
},
{
$sort: { "_id.date": 1}
}
]);
I basically need this on MongoDB:
history = history.filter((item, index) => {
if(index === 0) {
return item;
} else {
if(history[index-1]._id.floor_price !== item._id.floor_price) {
return item;
}
}
})
Thanks!