title: MongoDB - how to join parent and child products by reference
body: <p>my mongo collection stores products. There are two product types: child and parent. Parent product holds array of its child as reference.</p>
  
  <p>Use case:</p>
  
  <pre><code>use mydb;
  
  child1 = {
      _id: 1,
      name: "Child 1",
      is_child: true,
      is_parent: false,
      children : []
  }
  
  child2 = {
      _id: 2,
      name: "Child 2",
      is_child: true,
      is_parent: false,
      children : []
  }
  
  parent = {
      _id: 3,
      name: "Parent product",
      is_child: false,
      is_parent: true,
      children : [1, 2]
  }
  
  db.product.insert( [child1, child2, parent] );
  </code></pre>
  
  <p>And I'm looking for any query returning</p>
  
  <pre><code>{
      _id: 3,
      name: "Parent product",
      is_child: false,
      is_parent: true,
      children: [
          {
              _id: 1,
              name: "Child 1",
              is_child: true,
              is_parent: false,
              children : []
          },
          {
              _id: 2,
              name: "Child 2",
              is_child: true,
              is_parent: false,
              children : []
          }
      ] 
  }
  </code></pre>
  
  <p>I'm newbie to mongodb, but I guess an usage of map-reduce could solve the problem. Can anyone advice? Thx</p>