I have an aggregate query that is doing exactly what I want up to this point, but I am stuck transforming the data at the last step. I have the following:
{
"name": "a",
"tasks": [ { .. }, { .. }]
},
{
"name": "b",
"tasks": [ { .. }, { .. }]
}
all I need to do is map each entry in tasks to a separate result. Sounds incredibly simple to me.
The expected output should be
{ "name": "a", "task": { .. } },
{ "name": "a", "task": { .. } },
{ "name": "b", "task": { .. } },
{ "name": "b", "task": { .. } }
I tried using { $unwind: '$tasks' } in hopes that I could get separate entries, but it only seems to expand the first result. I only get the tasks from a.
I also tried $map but had similar problems.
If necessary, there is an _id inside of each task that could be used for uniqueness. Thats really what I'm trying to accomplish, a map of key-value pairs such as
{ "_id": "idFromTheTask", "name": "a" }