I've worked exclusively with RDBMSs for the past 10 years and am trying to explore something new to me like MongoDB. I’m trying to learn about data model design in this environment and because normalization is so engrained in my brain, it feels weird to denormalize and know how and when to do it. A number of questions are coming to mind:
- What is Mongo’s answer for modeling a one-to-many relationship?
- What is Mongo’s answer for modeling many-to-many relationships?
- So, if I have a
userscollections and a
commentscollection, where as user has many comments, and a
userdocument, how do we join this data functionally in code? For each comment displayed, do we “query” the users collection to retrieve their associated username? Or do we embed that user’s username directly into the
commentsand then push an update to the embedded username in
commentsin the event that the user’s username would change?
- How do we make a decision about when to embed information versus creating a new collection?