Am new to MongoDB and I have two arrays in a document like this. I want to get a specific value from both arrays. For example "received_bytes" and its value from the values array "43118304". I did some research but I think am lost.
fields:{
"time",
"received_bytes",
"sent_bytes"
}
values:{
"2021-11-22T08:08:30Z",
43118304,
43105744
}
Basic aggregate I have done
return await Metric.aggregate([
{
$match: matches,
},
{ $sort: { _id: 1 } },
{
$group: {
_id: params.field, // received_bytes
values: { $push: '$values' }, // array of values for received_bytes
},
},
]);
What i expect:
{
_id:"received_bytes",
values:[] //all received_bytes values
}
Thanks for help.