I have a collection lanes which has documents of following structure. Only the dist and time of new documents changes. I want to calculate average-speeds of all lanes grouped by l_id.
{
_id: 1213,
ab:[
{
l_id: 101,
dist: 100,
time: 100
},
{
l_id: 102,
dist: 140,
time: 120
},
{
l_id: 103,
dist: 10,
time: 10
}
]
}
like this :
{[
{
l_id: 101,
avgspeed: 14
},
{
l_id: 102,
avgspeed: 19
},
{
l_id: 103,
avgspeed: 9
}
]}
How can it be done using mongo aggregate/unwind query?
EDIT 1: (how to do it the structure is as follows)
{
_id: 1213,
ab:[
{
l_id: 101,
data:[{
dist: 100,
time: 100
}]
},
{
l_id: 102,
data:[{
dist: 140,
time: 120
}]
},
{
l_id: 103,
data:[{
dist: 10,
time: 10
}]
}
]
}