mongo $unwind and $group
<p>I have two collections. One of which I wish to add a reference to the other and have it populated on return. </p>

<p>Here is an example json I am trying to achieve as the result:</p>

<pre><code>{
  "title": "Some Title",
  "uid": "some-title",
  "created_at": "1412159926",
  "updated_at": "1412159926",
  "id": "1",
  "metadata": {
    "date": "2016-10-17",
    "description": "a description"
  },
  "tags": [
    {
      "name": "Tag 1",
      "uid": "tag-1"
    },
    {
      "name": "Tag 2",
      "uid": "tag-2"
    },
    {
      "name": "Tag 3",
      "uid": "tag-3"
    }
  ]
}
</code></pre>

<p>Here is the mongo query I have which gets my close, but it nests the original body of the item within the <code>_id</code> object. </p>

<pre><code>db.tracks.aggregate([{
    $unwind: "$tags"
}, {
    $lookup: {
        from: "tags",
        localField: "tags",
        foreignField: "_id",
        as: "tags"
    }
}, {
    $unwind: "$tags"
}, {
    $group: {
        "_id": {
            "title": "$title",
            "uid": "$uid",
            "metadata": "$metadata"
        },
        "tags": {
            "$push": "$tags"
        }
    }
}])
</code></pre>

<p>So the result is this:</p>

<pre><code>{
    "_id" : {
        "title" : "Some Title",
        "uid" : "some-title",
        "metadata" : {
            "date" : "2016-10-17",
            "description" : "a description"
        }
    },
    "tags" : [ 
        {
            "_id" : ObjectId("580499d06fe29ce7093fb53a"),
            "name" : "Tag 1",
            "uid" : "tag-1"
        }, 
        {
            "_id" : ObjectId("580499d06fe29ce7093fb53b"),
            "name" : "Tag 2",
            "uid" : "tag-2"
        }
    ]
}
</code></pre>

<p>Is there a way to achieve the desired output? Also is there a way to not have to define in the <code>$group</code> all the fields which I wish to return, I would like to return the original Object but with the referenced documents in the <code>tags</code> array.</p>