title: Mongo DB - sub-collections?
body: <p>I'm really new to MongoDb and am using it with nodeJS and the native node mongodb driver. I am having doubts about implementation. I hope you can help me:
  I have this "schema", where db.pages holds the config for each section of my website:</p>
  
  <pre><code>db.pages = [
     {name: 'contacts', settings:{...}},
     {name: 'blog', settings:{...}, posts: "blogPosts"},
     {name: 'media', settings: {...}, posts: "mediaPosts"}
  ]
  
  db.blogPosts = [
    {title: 'post1', date: '2011-10-22', author:'me', content: '...'},
    {title: 'post2', date: '2011-11-22', author:'me', content: '...'},
    {...............................................................}
  ];
  </code></pre>
  
  <p>What I'm doing here is, in each page, I define if I have a posts collection and, in node, when I load the page, I check if <code>page.posts</code> is defined and, if so, load the appropriate collection.</p>
  
  <p>Maybe I'm wrong, but this is looking too much as a relational thing so, my idea, would be to 
  put the content of <code>blogPosts</code> directly as the value for the prop <code>posts</code> of the <code>pages</code> collection, like so:</p>
  
  <pre><code>db.pages = [
         {name: 'contacts', settings:{...}},
         { name: 'blog', 
           settings:{...}, 
           posts: [
              {title: 'post1', date: '2011-10-22', author:'me', content: '...'},
              {title: 'post2', date: '2011-11-22', author:'me', content: '...'},
              {...............................................................}
           ]
         },
         {name: 'media', settings: {...}, posts: [...]}
      ]
  </code></pre>
  
  <p>I really think this makes much more sense, in a NoSQL environment, but I might be wrong. 
  The problem I am having is that using the latter configuration, I can't seem to make nodejs treat the <code>posts</code> field as a mongo collection.</p>
  
  <p>I hope this makes any sense to you and, if so, what I need to know is:</p>
  
  <ol>
  <li>Am I right or wrong to think the second way is the right way?</li>
  <li>How can I use node to read that 'sub-collection' as collection so I can apply a cursor and use <code>find()</code>, <code>sort()</code>, <code>limit()</code>, <code>skip()</code>, etc, on it...</li>
  </ol>