title: MongoDb Combine multiple results in a view
body: <p>In MongoDb I want to create a view that combines data from 2 collections.</p>
  
  <p>Structure:
  <strong>Event</strong> : Id, Name, Date, Locations(LocationId, Date), <strong>Location</strong> Id, Name. <strong>EventView</strong> : Name, Date, Locations(LocationName, Date).</p>
  
  <p>Example:</p>
  
  <p>Events: </p>
  
  <pre><code>[{ Id: 1, Name: 'Event 1', Date:'2019-01-16', [{ LocationId: 1, Date:'2019-01-16'}, { LocationId: 2, Date: '2019-01-17'}]}, { Id:1, Name: 'Event 2', Date:'2019-01-18', [{ LocationId: 1, Date:'2019-01-18'}]}]
  </code></pre>
  
  <p>Locations: </p>
  
  <pre><code>[{ Id: 1,  Name: 'London' }, { Id: 2,  Name: 'New York' }]
  </code></pre>
  
  <p>Current code</p>
  
  <pre><code>db.createView("EventView", "Event",
  [
   { $lookup: { from: "Location", localField: "Locations.Id", foreignField: "Id", as: "locations" } },
   { $project: { Id: 1, Name: 1, Date: 1, Locations: 1, "locations.Id": 1, "locations.Name": 1 } }
  ]
  )
  </code></pre>
  
  <p>Current output:</p>
  
  <pre><code>[{ Name: 'Event 1', Date: '2019-01-16', Locations:[{ LocationId: 1, Date: '2019-01-16' }, { LocationId: 2, Date: '2019-01-17' }], locations: [{ Id: 1, Name: 'London' }, { Id: 2, Name: 'New York' }]}, { Name: 'Event 2', Date: '2019-01-18', Locations: [{ LocationId: 1, Date:'2019-01-18' }], locations: [{ Id: 1, Name: 'London' }]}]
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>[{ Name: 'Event 1', Date: '2019-01-16', Locations:[{ LocationName: 'London', Date: '2019-01-16' }, { LocationName: 'New York', Date: '2019-01-17' }]}, { Name: 'Event 2', Date: '2019-01-18', Locations: [{ LocationName: 'London' Date:'2019-01-18' }]}]
  </code></pre>
  
  <p><strong>Q</strong>: What do I need to change in the code so that the <strong>Locations</strong> property is mapped as in the desired output example?</p>