title: How to build a recursive structure with MongoDB
body: <p>I'm trying to do something usually simple with SQL (with foreign key in the same table for example) (it may be as easy with MongoDB, I just don't know yet) which is to build a recursive data structure.</p>
  
  <p>For this example, I'll talk about Pages in a Website. I'd like to make a multiple level page structure. So there could be:</p>
  
  <ul>
  <li>Home</li>
  <li>Our Products
  <ul>
  <li>Product 1</li>
  <li>Product 2</li>
  </ul></li>
  <li>About us
  <ul>
  <li>Where are we?</li>
  <li>Contact us</li>
  </ul></li>
  </ul>
  
  <p>Let's say pages would have a title and a content.</p>
  
  <p>I need to know what's the best way to do this, and also how I could build a sitemap based on that data structure (page that shows every page from every level).</p>
  
  <p>I'm building a node.js app with MongoDB for this case.</p>
  
  <p>EDIT: Wouldn't it work by simply referencing a parent page in each page? Pages would be like <code>{ title: 'test', content: 'hello world', parentPage: ObjectID(parent page) }</code></p>
  
  <p>Thanks for the help!</p>