I have a Devices collection in MongoDB with the following structure:
{
"group": [
"group1"
]
},
{
"group": [
"group1",
"group2"
]
},
{
"group": []
},
{
"group": [
"group3",
"group4"
]
}
How can I filter or aggregate the documents so that I only return the last element of each group array including the blank arrays?
Expected result:
["group1", "group2", "", "group4"]