QuickDevGuide

Home › NoSQL Database

Schema Design Patterns — NoSQL Database

MongoDB schema design is fundamentally different from SQL. Instead of normalizing data across tables, you design based on how your application queries data. When to Embed Embed (denormalize) when data is frequently accessed together, there is a 1:1 or 1:few relationship, and the embedded data doesn't grow without bound. Example: user addresses, order line items. When to Reference Reference (normalize) when data is accessed independently, there is a 1:many or many:many relationship, or the related data is large/grows unboundedly. Example: user's posts (reference), post comments (embed if few, reference if many). Anti-pattern Unbounded arrays — if a document's array can grow indefinitely, it will eventually exceed MongoDB's 16MB document size limit. Move such data to a separate collection…

Key Takeaways