node.js - Mongo DB - sub-collections? -


i'm new mongodb , using nodejs , native node mongodb driver. having doubts implementation. hope can me: have "schema", db.pages holds config each section of website:

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: '...'},   {...............................................................} ]; 

what i'm doing here is, in each page, define if have posts collection and, in node, when load page, check if page.posts defined and, if so, load appropriate collection.

maybe i'm wrong, looking relational thing so, idea, put content of blogposts directly value prop posts of pages collection, so:

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: [...]}     ] 

i think makes more sense, in nosql environment, might wrong. problem having using latter configuration, can't seem make nodejs treat posts field mongo collection.

i hope makes sense and, if so, need know is:

  1. am right or wrong think second way right way?
  2. how can use node read 'sub-collection' collection can apply cursor , use find(), sort(), limit(), skip(), etc, on it...

first approach better. second approach has multiple drawbacks:

  1. each document has size limit of 16mb. hit limit , not able add more blog posts
  2. you cannot query , fetch individual blog posts disk in 1 big document
  3. if apply principle, put comments in same pages document, further complicating , loose lot of flexibility

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -