title: Use lookup in an array of objects with ids
body: <p>I have a problem using lookup in an array of objects.</p>
  
  <p>My struct is</p>
  
  <pre><code>type MerchantList struct {
      MerchantID       bson.ObjectId    `json:"merchantId,omitempty" bson:"merchantId,omitempty"`
      Merchant         *Merchant        `json:"merchant,omitempty" bson:"merchant,omitempty"`
      MerchantRevenue  float64          `json:"merchantRevenue" bson:"merchantRevenue"`
      MerchantFee      int              `json:"merchantFee,omitempty" bson:"merchantFee,omitempty"`
  }
  
  type Weeks struct {
      ID               bson.ObjectId    `json:"id,omitempty" bson:"_id,omitempty" description:"Object ID"`
      MerchantList     []*MerchantList  `json:"merchantList,omitempty" bson:"merchantList,omitempty"`
      CreatedAt        int64            `json:"createdAt" bson:"createdAt" description:"Created date."`
      UpdatedAt        int64            `json:"updatedAt" bson:"updatedAt" description:"Updated date."`
  }
  </code></pre>
  
  <p>I have a collection structured as follows:</p>
  
  <pre><code>{
      "_id" : ObjectId("5af8bdb20b0aa02928514a00"),
      "name" : "Week 1",
      "merchantList" : [ 
          {
              "merchantId" : ObjectId("5ad79c500b0aa07ed040fe4b"),
              "merchantRevenue" : 126500.0,
              "merchantFee" : 25
          }
      ]
  }
  </code></pre>
  
  <p>My query is </p>
  
  <pre><code>pipe := []bson.M{
      {"$unwind": bson.M{
          "path": "$merchant.merchantList",
          "preserveNullAndEmptyArrays": true}},
      {"$lookup": bson.M{
          "from":         "merchant",
          "localField":   "merchantList.merchantId",
          "foreignField": "_id",
          "as":           "merchant",
      }},
  }
  </code></pre>
  
  <p>I would expect an exit from the program something like that</p>
  
  <pre><code>{
      "items": [
          {
              "id": "5af8bdb20b0aa02928514a00",
              "merchantList": [
                  {
                      "merchantId": "5ad79c500b0aa07ed040fe4b",
                      "merchant": {
                          "name": "Merchant 1"
                      }
                  }
              ],
          }
      ]
  }
  </code></pre>
  
  <p>If anyone has any idea how to do it. It would be very helpful :)</p>