Reputation: 11598
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:
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, I define if I have a posts collection and, in node, when I load the page, I check if page.posts
is defined and, if so, load the appropriate collection.
Maybe I'm wrong, but this is looking too much as a relational thing so, my idea, would be to
put the content of blogPosts
directly as the value for the prop posts
of the pages
collection, like 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 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 posts
field as a mongo collection.
I hope this makes any sense to you and, if so, what I need to know is:
find()
, sort()
, limit()
, skip()
, etc, on it...Upvotes: 12
Views: 12989
Reputation: 4228
First approach is better. Second approach has multiple drawbacks:
Upvotes: 12