title: Mongodb aggregate lookup return only one field of array
body: <p>i have some collections for our project. </p>
  
  <ul>
  <li>Casts collection contains movie casts</li>
  <li>Contents collection contains movie contents</li>
  </ul>
  
  <p>i want to run aggregate lookup for get information about movie casts with position type.</p>
  
  <p>i removed collections details unnecessary fields.</p>
  
  <p>Casts details:</p>
  
  <pre><code>{
      "_id" : ObjectId("5a6cf47415621604942386cd"),
      "fa_name" : "",
      "en_name" : "Ehsan",
      "fa_bio" : "",
      "en_bio" : ""
  }
  </code></pre>
  
  <p>Contents details:</p>
  
  <pre><code>{
      "_id" : ObjectId("5a6b8b734f1408137f79e2cc"),
  
      "casts" : [ 
          {
              "_id" : ObjectId("5a6cf47415621604942386cd"),
              "fa_fictionName" : "",
              "en_fictionName" : "Ehsan2",
              "positionType" : {
                  "id" : 3,
                  "fa_name" : "",
                  "en_name" : "Director"
              }
          }, 
          {
              "_id" : ObjectId("5a6cf47415621604942386cd"),
              "fa_fictionName" : "",
              "en_fictionName" : "Ehsan1",
              "positionType" : {
                  "id" : 3,
                  "fa_name" : "",
                  "en_name" : "Writers"
              }
          }
      ],
      "status" : 0,
      "created" : Timestamp(1516997542, 4),
      "updated" : Timestamp(1516997542, 5)
  }
  </code></pre>
  
  <p>when i run aggregate lookup with bellow query, in new generated lookup array only one casts contents If in accordance with above casts array value aggregate lookup should return two casts content with two type. in casts array value exists two type of casts, 1) writers and directors. but returned director casts content. _casts should contains two object not one object!</p>
  
  <p>aggregate lookup query:</p>
  
  <pre><code>{$lookup:{from:"casts",localField:"casts._id",foreignField:"_id",as:"_casts"}}
  </code></pre>
  
  <p>result:</p>
  
  <pre><code>{
          "_id" : ObjectId("5a6b8b734f1408137f79e2cc"),
  
          "casts" : [ 
              {
                  "_id" : ObjectId("5a6cf47415621604942386cd"),
                  "fa_fictionName" : "",
                  "en_fictionName" : "Ehsan2",
                  "positionType" : {
                      "id" : 3,
                      "fa_name" : "",
                      "en_name" : "Director"
                  }
              }, 
              {
                  "_id" : ObjectId("5a6cf47415621604942386cd"),
                  "fa_fictionName" : "",
                  "en_fictionName" : "Ehsan1",
                  "positionType" : {
                      "id" : 3,
                      "fa_name" : "",
                      "en_name" : "Writers"
                  }
              }
          ],
      "_casts" : [ 
             {
              "_id" : ObjectId("5a6cf47415621604942386cd"),
              "fa_name" : "",
              "en_name" : "Ehsan",
              "fa_bio" : "",
              "en_bio" : ""
             }
          ],
          "status" : 0,
          "created" : Timestamp(1516997542, 4),
          "updated" : Timestamp(1516997542, 5)
      }
  </code></pre>
  
  <p><strong>EDIT-1</strong>
  finally my problem is solved. i have only one problem with this query, this query doesn't show root document fields. finally solve this problem. finally query exists in EDIT-2.</p>
  
  <p>query:</p>
  
  <pre><code>db.contents.aggregate([ 
  {"$unwind":"$casts"},
  {"$lookup":{"from":"casts","localField":"casts._id","foreignField":"_id","as":"casts.info"}},
  {"$unwind":"$casts.info"},
  {"$group":{"_id":"$_id", "casts":{"$push":"$casts"}}},
  ])
  </code></pre>
  
  <p><strong>EDIT-2</strong></p>
  
  <pre><code>db.contents.aggregate([ 
  {"$unwind":"$casts"},
  {"$lookup":{"from":"casts","localField":"casts._id","foreignField":"_id","as":"casts.info"}},
  {"$unwind":"$casts.info"},
  {$group:{"_id":"$_id", "data":{"$first":"$$ROOT"}, "casts":{"$push":"$casts"}}},
  {$replaceRoot:{"newRoot":{"$mergeObjects":["$data",{"casts‌​":"$casts"}]}}},
  {$project:{"casts":0}}
  ]).pretty()
  </code></pre>