title: iterating tree in mongoDB
body: <p>I have a collection of data like this(for example) :</p>
  
  <pre><code>{
      name : "john" ,
      _id : "0"
  },
  {
      name : "Richard" ,
      parent_id : "0" ,
      _id : "1"
  },
  {
      name : "Kevin" ,
      parent_id : "0" ,
      _id : "2"
  },
  {
      name : "William" ,
      parent_id : "1" ,
      _id : "3"
  },
  {
      name : "George" ,
      parent_id : "3" ,
      _id : "4"
  }
  </code></pre>
  
  <p>I'm trying to write a function to receive an <code>_id</code> and return all children in any depth of this node, for example for <code>_id = 0</code> I need something like this :</p>
  
  <pre><code>[
      {
          name : "Richard" ,
          parent_id : "0" ,
          depth : "1" ,
          _id : "1"
      },
      {
          name : "Kevin" ,
          parent_id : "0" ,
          depth : "1" ,
          _id : "2"
      },
      {
          name : "William" ,
          parent_id : "1" ,
          depth : "2" ,
          _id : "3"
      },
      {
          name : "George" ,
          parent_id : "3" ,
          depth : "3" ,
          _id : "4"
      }
  ]
  </code></pre>
  
  <p>I write several recursive functions to iterate on my mongodb docs but the main problem is I can't handle callbacks (asynchronous) and don't know when and how can I end the recursive function.</p>
  
  <p>How can I do this with mongodb and node.js?
  Any idea can be useful ,thanks.</p>