title: MongoDb $lookup query with multiple fields from objects array
body: <p>This question has previously been marked as a duplicate of <a href="https://stackoverflow.com/questions/34967482/lookup-on-objectids-in-an-array"><strong>this question</strong></a> I can with certainty confirm that it is not.</p>
  
  <p>This is not a duplicate of the linked question because the elements in question are not an array but embedded in individual objects of an array as fields. I am fully aware of how the query in the linked question should work, however that scenario is different from mine.</p>
  
  <p>I have a question regarding the <code>$lookup</code> query of MongoDb. My data structure looks as follows:</p>
  
  <p>My <strong>"Event"</strong> collection contains this single document:</p>
  
  <pre><code>{
     "_id": ObjectId("mongodbobjectid..."),
     "name": "Some Event",
     "attendees": [
          {
             "type": 1,
             "status": 2,
             "contact": ObjectId("mongodbobjectidHEX1")
          },
          {
             "type": 7,
             "status": 4,
             "contact": ObjectId("mongodbobjectidHEX2")
          }
      ]
  }
  </code></pre>
  
  <p>My <strong>"Contact"</strong> collection contains these documents:</p>
  
  <pre><code>{
      "_id": ObjectId("mongodbobjectidHEX1"),
      "name": "John Doe",
      "age": 35
  },
  {
      "_id": ObjectId("mongodbobjectidHEX2"),
      "name": "Peter Pan",
      "age": 60
  }
  </code></pre>
  
  <p>What I want to do is perform an <code>aggregate</code> query with the <code>$lookup</code> operator on the <strong>"Event"</strong> collection and get the following result with full "contact" data:</p>
  
  <pre><code>{
     "_id": ObjectId("mongodbobjectid..."),
     "name": "Some Event",
     "attendees": [
          {
             "type": 1,
             "status": 2,
             "contact": {
                "_id": ObjectId("mongodbobjectidHEX1"),
                "name": "John Doe",
                "age": 35
             }
          },
          {
             "type": 7,
             "status": 4,
             "contact": {
                "_id": ObjectId("mongodbobjectidHEX2"),
                "name": "Peter Pan",
                "age": 60
             }
          }
      ]
  }
  </code></pre>
  
  <p>I have done the same with single elements of "Contact" referenced in another document but never when embedded in an array. I am <strong>unsure of which pipeline arguments to pass</strong> to get the above shown result?</p>
  
  <p>I also want to add a <code>$match</code> query to the pipeline to filter the data, but that is not really part of my question.</p>