For example, if I have a document like this
{ a: 1, subdoc: { b: 2, c: 3 } }
How can I convert it into a
I guess the easiest way is altering the result after it returns, using map.
map
collection.mapFunction = function(el) { el.b = el.subdoc.b; el.c = el.subdoc.c delete(el.subdoc); return el; } ... var result = await collection.aggregate(...).toArray(); result = result.map(collection.mapFunction);