title: mongoDB, update an object from a related collection
body: <p>I have a collection with a nested object, the current collection stored an object without an _id for that object. So now I have 1000+ records with nested objects. </p>
  
  <p>I have a master lookup collection, where these nested objects came from.</p>
  
  <p>so the data looks like this:</p>
  
  <pre><code>{
      _id:
      name:
      thing: {
          family:
          type:
      }
  }
  </code></pre>
  
  <p>The master "Thing" data looks like this:</p>
  
  <pre><code>{
      _id:
      family:
      type:
  }
  </code></pre>
  
  <p>What I want to do is up data ALL the documents with "thing" data INCLUDIING the _id so my resulting data will look like this:</p>
  
  <pre><code>{
      _id:
      name:
      thing: {
          _id: (from the Things collection)
          family:
          type:
      }
  }
  </code></pre>
  
  <p>If I were doing this in SQL it would look like this:</p>
  
  <pre><code>UPDATE collection
  SET 
      thing_id = (
          SELECT _id
          FROM Things
          WHERE family = thing_family
          AND type = thing_type
      ) 
  </code></pre>
  
  <p>How do I do a similar update in MongoDB??</p>