title: Resolve each ObjectId in an array field to an object from another collection
body: <p>This is quite a specific problem and I have been trawling stack overflow for hours looking for a solution.</p>
  
  <p>I have two collections:</p>
  
  <p>events:</p>
  
  <pre><code>{   
      _id : ObjectId,
      title : $title,
      other fields etc...,
      artist : ObjectId,
      targets : [ObjectId,ObjectId,ObjectId]
  }
  </code></pre>
  
  <p>artists:</p>
  
  <pre><code>{   
      _id : ObjectId,
      name : $name,
      other fields etc...
  }
  </code></pre>
  
  <p>each event has a field with multiple targets, saved as ObjectId's. I need a query using some combination of aggregation and <code>$lookup</code> to return an event (matched with <code>.find( { _id : ObjectId_of_event } )</code> with each target resolved to an object</p>
  
  <p>it would hopefully resemble this:</p>
  
  <pre><code>{   _id : ObjectId,
      title : $title,
      other fields...,
      targets : [ {   
                     _id : ObjectId_1,
                     name : $name,
                     other fields etc...
                  },
                  {   
                     _id : ObjectId_2,
                     name : $name,
                     other fields etc...
                  },
                  {   
                     _id : ObjectId_3,
                     name : $name,
                     other fields etc...
                  } ]
  }
  </code></pre>
  
  <p>I have tried aggregating, applying a <code>$lookup</code> and then using <code>$group</code> in the mongodb pipeline but have not found a way to keep all of the targets in the targets array and just resolve each ObjectId.</p>
  
  <p>//edit extra info</p>
  
  <p>the query I am currently running:</p>
  
  <pre><code>db.collection("events").aggregate([
       { $match: { _id : object } }, 
       { $lookup : { 
                    from: "artists",
                    localField: "artist",
                    foreignField: "_id",
                    as: "artist_object" 
       }},
       { $unwind : "$targets"},
       { $lookup : { 
                    from: "artists",
                    localField: "targets",
                    foreignField: "_id",
                    as: "targets_objects" 
                   }} 
        }} ]).toArray(function(queryErr, main_event) etc... 
  </code></pre>
  
  <p>which returns:</p>
  
  <pre><code>     [ { event : { _id : ObjectId,
                    title : $title,
                    artist : ObjectId,
                    targets : { artist_object_of_first_target }
                    artist_object : { artist object }
         },
         { event : { _id : ObjectId,
                    title : $title,
                    artist : ObjectId,
                    targets : { artist_object_of_second_target }
                    artist_object : { artist object }
         },
         { event : { _id : ObjectId,
                    title : $title,
                    artist : ObjectId,
                    targets : { artist_object_of_third_target }
                    artist_object : { artist object }
         }]
  </code></pre>
  
  <p>Could anyone point me in the right direction?</p>