MongoDB - Data Modelling

MongoDB - Data Modelling Let’s now understand the structural aspects of MongoDB

Data in MongoDB has a flexible schema.documents in the same collection

Some considerations while designing Schema in MongoDB

  • Design your schema according to user requirements.

  • Combine objects into one document if you will use them together. Otherwise separate them (but make sure there should not be need of joins).

  • Duplicate the data (but limited) because disk space is cheap as compare to compute time.

  • Do joins while write, not on read.

  • Optimize your schema for most frequent use cases.

  • Do complex aggregation in the schema.


Suppose a client needs a database design for his blog/website and see the differences between RDBMS and MongoDB schema design.
  • Every post has the unique title, description and CONTENT.
  • Every post can have one or more CONTENT.
  • Every post has the name of its publisher and total number of dislikes.
  • Every post has comments given by users along with their name, message, data-time and dislikes.
  • On each post, there can be zero or more comments.
In RDBMS schema, design for above requirements will have minimum three tables. While in MongoDB schema, design will have one collection post and the following structure
    _id: POST_ID
    title: TITLE_OF_POST,
    description: POST_DESCRIPTION,
    by: POST_BY,
    url: URL_OF_POST,
    dislikes: TOTAL_DISLIKE,
    comments: [
            message: TEXT,
            dateCreated: DATE_TIME,
            dislike: DISLIKE
            message: TEXT,
            dateCreated: DATE_TIME,
            dislike: DISLIKE

Welookups is optimized for learning.Copy right 2018 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.