title: MongoDB inserting child document on ID reference
body: <p>I migrated my SQL database into a MongoDB database for a project. It migrated the foreign keys as the ID's that were already there. For example I have these two columns linked through the driversId:
  <a href="https://i.stack.imgur.com/EdJcX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EdJcX.png" alt="enter image description here" /></a></p>
  <p>My question is how do I get the driver as a document in the driver_standings collection? Thanks in advance!</p>
  <p>Edit: I've used the answer below with $merge to update the collection:</p>
  <pre><code>db.driverstandings.aggregate([{
    $lookup: {
      from: &quot;drivers&quot;,
      localField: &quot;driverId&quot;,
      foreignField: &quot;driverId&quot;,
      as: &quot;driver&quot;
    }
  }, { $merge: { into:&quot;driverstandings&quot; } }
  ])
      
  </code></pre>