title: Mongodb query join optimization
body: <p>Lets say I have 3 collections: </p>
  
  <pre><code>Grandparents
  {
   _id:1,
   name:old foo
  }
  
  Parents
  {
  _id:2,
  grandparentId:1,
  name: foo
  }
  Person
  {
  _id: 3,
  parentId:2,
  name: youngfoo
  }
  </code></pre>
  
  <p>How do i optimize a query to find all person where person's grandparent's name = x?</p>
  
  <p>Name is not unique in this case.</p>
  
  <p>What i can think of so far:<br>
  1. Query all grandparents with name = x<br>
  2. Query all parents where grandparent ids == grandparent ids gotten from step 1<br>
  3. Query all persons where parent ids == parent ids gotten from step 2.<br></p>
  
  <p>Doesn't feel very efficient. Can mongodb experts out there help me? Thanks!</p>