• Articles
  • Tutorials
  • Interview Questions

MongoDB Data Modeling Made Easy

How does MongoDB store data?

MongoDB stores data in the form of BSON -Binary encoded JSON documents which supports a huge rich collection of types. Namely Fields in BSON documents may hold arrays of values or embedded documents as requirement. In MongoDB the data base construct in such a way as a group of related collections. Each database has a distinct and informative set of data files and can contain a large number of collections. A single MongoDB deployment consists of many databases.

Watch this MongoDB video

Video Thumbnail

What is a ‘document’ in MongoDB?

A record in MongoDB is a document which is been described below and a data structure composed of field and value pairs. MongoDB documents are very similar to JSON objects. The values of fields may consist of other such as documents, arrays, and arrays of documents. This is an important differentiation and vital feature devised from RDBMS systems where each field must contain only one value.
data models
Data stored in MongoDB has a flexible schema. Documents are fetched in the same collection. They don’t require same set of fields or structure, common fields in a collection’s documents which consist of different types of data.

Some  considerations while designing Schema in MongoDB

  • Design your schema according to user requirements.
  • Combine objects into single document if it is required to use together. Otherwise separate them without using joins.
  • Duplicate the data but only limited stuffs because disk space is cheaper compared to compute time.
  • Usage of joins implemented while write operation, not used on read.
  • Optimize your schema for most frequent use cases.
  • Complex aggregation is encouraged in the schema.

Certification in Bigdata Analytics

Consider the example

A client needs a database design for his blog or website creation and then notice the differences between RDBMS and MongoDB schema design.

  • Every post has the unique title, description and URL as per the requirement.
  • Every post can have more than one tags.
  • Every post has the name of its publisher and total number of likes given per post.
  • Every post has respective comments given by users along with their name, message, data-time and likes given for post.
  • On each post, there can be zero or any more comments.
  • In RDBMS schema, design for above requirements will be consisting of minimum three tables.

data models

Course Schedule

Name Date Details
Big Data Course 21 Dec 2024(Sat-Sun) Weekend Batch View Details
28 Dec 2024(Sat-Sun) Weekend Batch
04 Jan 2025(Sat-Sun) Weekend Batch

About the Author

Technical Research Analyst - Big Data Engineering

Abhijit is a Technical Research Analyst specialising in Big Data and Azure Data Engineering. He has 4+ years of experience in the Big data domain and provides consultancy services to several Fortune 500 companies. His expertise includes breaking down highly technical concepts into easy-to-understand content.