1

I come from an SQL background, where grasping the possible relationships between different models and schemas seems to be quite straightforward to me.

How can I shift the same thing to the MEAN world? For example, let's just assume I have a basic blog engine with a posts table and a comments table, where posts have many comments and each comment has a post. While coding this is easy in, say, Rails, I'm getting stuck here and couldn't find good tutorials.

Also, I'm not sure if adding authors to the party is any more complicated - let's just say posts and comments each have an author, and the author has many comments and also has many posts (once I get this I think highlighting "OP" comments is just the matter of a query).

Can you give me a guideline regarding the differences between what I've been used to in Rails and the approach I need now?

Community
  • 1
  • 1
zcserei
  • 577
  • 7
  • 30
  • 1
    Perhaps the series **6 Rules of Thumb for MongoDB Schema Design:** [**Part 1**](http://blog.mongodb.org/post/87200945828/6-rules-of-thumb-for-mongodb-schema-design-part-1), [**Part 2**](http://blog.mongodb.org/post/87892923503/6-rules-of-thumb-for-mongodb-schema-design-part-2) and [**Part 3**](http://blog.mongodb.org/post/88473035333/6-rules-of-thumb-for-mongodb-schema-design-part-3) may be of interest to you? – chridam Jun 26 '15 at 15:08
  • thanks, that seems interesting (crossed part I before), though I'd like to see it in application – zcserei Jun 26 '15 at 15:09
  • 1
    Also relevant is [MongoDB relationships: embed or reference?](http://stackoverflow.com/questions/5373198/mongodb-relationships-embed-or-reference) – JohnnyHK Jun 26 '15 at 15:13
  • Sorry. Too broad, and I doubt anyone can answer here within the space allowed for posts on stackoverflow for anything worth mentioning ( and really people, you just cannot post anything worth a reward here). Search for blog posts. But start with reading: [Data Modelling](http://docs.mongodb.org/manual/core/data-modeling-introduction/) from the core documentation. And actually read **all** of the sections and don't skim. – Blakes Seven Jun 26 '15 at 15:26

1 Answers1

-2

You are used to think in terms of normalization. NoSQL databases let you design your data model in structured documents, meaning you can denormalize your data. It has advantages like data locality and atomicity, but can suffer from redundancy and inconsistency.

An example would be embedding the comments inside each post. Thus, you don't have several collections / tables, and can access your data swiftly.

I advice you to read the book MongoDB Applied Design Patterns to better understand the benefits you would earn.

TechWisdom
  • 3,960
  • 4
  • 33
  • 40
  • Sort of a "long comment" really rather than the definitive answer people are alll searching for. Don't you think? Some questions should be considered for what they are actually asking might take pages and pages of information and examples that a SO answer just does not give the provision for. – Blakes Seven Jun 26 '15 at 15:33
  • @BlakesSeven, What do you mean? What would you change? – TechWisdom Jun 27 '15 at 15:09
  • Dear downvoters, at least give your feedback to teach me something – TechWisdom Jun 29 '15 at 19:55