Notes on learning MongoDB database design

Last updated on 18th Oct. 2024
Oct. 15th and 16th:

As I have done a quick refresh and slightly improved my SQL database design knowledge over past few days, I felt that I should also get some exposure to MongoDB database design. So far, I have used fairly simple MongoDB schemas in the tutorial projects I have gone through and perhaps some simple project variations that I did. I need to get more exposure. This post has related notes.

MongoDB Schema Design Best Practices, https://www.youtube.com/watch?v=QAqK-R9HUhc by MongoDB, around 10 mins, April 2021


https://www.mongodb.com/resources/solutions/use-cases/mongodb-application-modernization-guide - Downloaded file: MongoDB_Modernization_Guide-ans0zbdf0i.zip has RDBMS to MongoDB Migration White Paper.pdf and other files including sample DB.

RDBMS to MongoDB Migration White Paper.pdf - 20 pages: Has examples of simple to medium complexity RDBMS design along with MongoDB schemas ('converted'); "The $lookup aggregation pipeline stage provides JOIN capabilities in MongoDB, supporting the equivalent of SQL subqueries and non-equijoins."; Embedding vs. Referencing; "The RDBMS optimizes data storage efficiency (as it was conceived at a time when storage was the most expensive component of the system.".."MongoDB’s document model is optimized for how the application accesses data (as performance, developer time, and speed to market are now more important than storage volumes)."; covers indexing options; "The MongoDB Compass GUI visualizes explain output, making it even easier for you to identify and resolve performance issues. The MongoDB Query Profiler helps expose performance issues by displaying slow-running queries (by default, queries that exceed 100ms) and their key performance statistics directly in the UI."

https://www.mongodb.com/docs/manual/data-modeling/ seems to be extensive. Perhaps it may be a must-read for me before doing a medium or higher complexity MongoDB database design.






Quick intro. kind-of article: Data Modelling in MongoDB, https://www.geeksforgeeks.org/mongodb-data-modelling/ , LU May 2024.

Data Modeling with MongoDB, https://www.youtube.com/watch?v=3GHZd0zv170, by MongoDB, around 35 mins., Oct. 2020. 
Fast paced video; some examples are simple; some topics especially related to performance are complex. Not really a tutorial kind of video but more of an expert providing tips along with some nice explanations. Perhaps the speaker had to compress a lot of topics in a short video. Note that the official learning data modelling video set (MongoDB Data Modeling Path) is 9 hours long. That probably is more like a tutorial. But viewing this video is useful as one gets rapid exposure to some probably important aspects of MongoDB data modelling. The speaker is clearly very knowledgeable and expresses herself very well.
==========

Most of the Mongoose/MongoDB schemas that I have seen in the tutorials are flat (if that's the word) without any embedding - i.e. they are like tables in a relational database. I quickly went through the few projects source code of Smilga Express tutorial that I had not yet seen, looking only at the models there. I found only one embedded schema case.
10-e-commerce-api\final\models\Order.js has an Order schema with orderItems field being an array of SingleOrderItemSchema.

Bhagavad Gita API https://github.com/vedicscriptures/bhagavad-gita-api.git also uses 'flat' schemas (no embedding).
=================================
Oct. 18th 2024 Update

From Oct. 16th, have started going through MongoDB Data Modeling Path, https://learn.mongodb.com/learning-paths/data-modeling-for-mongodb?sessionFields=%5B%5B%22format%22%2C%22Free%22%5D%5D , 9 hours, free ... Have done/partially done (so far it is an easy paced and good tutorial):
* Data Modeling for MongoDB Overview, 3 mins.

* Identifying Database Workloads (first step of data modelling as per MongoDB), 30 mins. 
* Modeling Data Relationships
* Schema Design Patterns
Related to lesson 1 above:
Introduction to the MongoDB Aggregation Framework, https://www.mongodb.com/developer/products/mongodb/introduction-aggregation-framework/ , CD:Feb 2022, LUD: Sept. 2022 ... This has code like:
{
"_id":{
"$oid":"56e9b39b732b6122f877fa31"
 },
"airline":{
"id":{
"$numberInt":"410"
},
----
Aggregation Pipeline, https://www.mongodb.com/docs/manual/core/aggregation-pipeline/ has some simple examples and also explains field paths which use $ symbol.



=========================================
I am suspending my MongoDB tutorial learning here as something else has cropped up which I need to focus on.

Comments