I don't know if this is possible to do, but suppose I have documents like these:
[
{
"L": [
{
"L1": 1
},
{
"L6": 2
},
{
"L2": 1
}
],
"week": 26,
"weekEnd": "2020-06-28",
"weekStart": "2020-06-22"
},
{
"L": [
{
"L5": 1
},
{
"L2": 1
},
{
"L3": 1
}
],
"week": 19,
"weekEnd": "2020-05-10",
"weekStart": "2020-05-04"
},
]
As you all can see, the array Lcan have different objects with fields like L1, L2, L3, ..., L30.
I would like to pull out the fields of each object out of the L array.
Expected result:
[
{
"L1": 1,
"L6": 2,
"L2": 1,
"week": 26,
"weekEnd": "2020-06-28",
"weekStart": "2020-06-22"
},
{
"L5": 1,
"L2": 1,
"L3": 1,
"week": 19,
"weekEnd": "2020-05-10",
"weekStart": "2020-05-04"
}
]
I could do this "from scratch", but I would have to write every field one by one in a $project stage. Is there a automatic way of doing this?