title: MongoDB architecture best practices for storing child relationships?
body: <p>Say I need to store a manager/employee relationship in a mongoDB database and for the sake of example lets say these are two different collections.  I generally try to show this relationship by structuring the documents/db like this:</p>
  
  <p>manager collection document:</p>
  
  <pre><code>{
     id: 1,
     name: "Bill Smith"
  }
  </code></pre>
  
  <p>employee collection documents:</p>
  
  <pre><code>{
    id: 1,
    name: "Abe Smith",
    managerId: 1
  },
  {
    id: 2,
    name: "Hank Smith",
    managerId: 1
  }
  </code></pre>
  
  <p>But I often see people storing this relationship in this way:</p>
  
  <p><strong>Method #2</strong></p>
  
  <p>manager collection document:</p>
  
  <pre><code>{
    id: 1,
    name: "Bill Smith",
    employees: [1, 2]
  }
  </code></pre>
  
  <p>employee collection documents:</p>
  
  <pre><code>{
    id: 1,
    name: "Abe Smith"
  },
  {
    id: 2,
    name: "Hank Smith"
  }
  </code></pre>
  
  <p>The drawback that I see with the second method is that the <code>employees</code> array could get out of synch if an employee is deleted from it's collection but not the array.</p>
  
  <p>I'm curious if anyone can point out the pros/cons of the two different methods and if one is generally considered best practice for storing child relationships like this in MongoDB?</p>