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.
Building with Patterns: A Summary, https://www.mongodb.com/blog/post/building-with-patterns-a-summary
MongoDB University Free courses: https://learn.mongodb.com/catalog?labels=%5B%22Free%2FPaid%22%5D&values=%5B%22Free%22%5D
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
MongoDB Node.js Developer Path, https://learn.mongodb.com/learning-paths/mongodb-nodejs-developer-path?sessionFields=%5B%5B%22format%22%2C%22Free%22%5D%5D , 15 hours, free
SQL to MongoDB Mapping Chart, https://www.mongodb.com/docs/manual/reference/sql-comparison/
SQL to Aggregation Mapping Chart, https://www.mongodb.com/docs/manual/reference/sql-aggregation-comparison/
Transactions, https://www.mongodb.com/docs/manual/core/transactions/
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.
- Lesson 1: Identifying and Quantifying Entities
- Lesson 2: Identifying Reads and Writes
- Lesson 3: Quantifying Reads and Writes
- Additional Resources listed (have not gone through them):
- A Comprehensive Guide to Data Modeling, https://www.mongodb.com/resources/basics/databases/data-modeling
- Data Modeling, https://www.mongodb.com/docs/manual/data-modeling/
- The Principles of Data Modeling for MongoDB, https://www.youtube.com/watch?v=0XVmuyPGy-o , 27 min. 44 secs., Nov. 2022 by MongoDB (by Daniel Coupal) (Quickly browsed through it and seems to be impressive).
- Steve Hoberman, Pascal Desmarets, Daniel Coupal | MongoDB .Local NYC 2023, https://www.youtube.com/watch?v=TNGOzuZJg3E, 22 min. 44 secs., Jun. 2023 (Seems to cover a book published by the three: MongoDB Data Modeling and Schema Design, https://www.amazon.com/MongoDB-Data-Modeling-Schema-Design/dp/1634621980).
* Modeling Data Relationships
- Lesson 1: Identifying Relationships
- Lesson 2: Embedding or Referencing
- Lesson 3: Modeling One-to-One
- Lesson 4: Modeling One-to-Many
- Lesson 5: Modeling Many-to-Many
- Additional Resources listed (have not gone through them) (omitting book mentioned above which is repeated):
- Data Model Design, https://www.mongodb.com/docs/manual/data-modeling/#link-related-data
- Embed or Reference Guidelines PDF, https://learn.mongodb.com/learn/course/modeling-data-relationships/files [Just 1 key figure ... downloaded file: urok0pa98sl7-EmbedvsReference.pdf]
- Model one-to-one relationships with embedded documents, https://www.mongodb.com/docs/manual/tutorial/model-embedded-one-to-one-relationships-between-documents/
- Model one-to-many relationships with embedded documents, https://www.mongodb.com/docs/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/
- Model one-to-many relationships with document references, https://www.mongodb.com/docs/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/
* Schema Design Patterns
- Lesson 1: Inheritance Pattern (second part of this video gets into aggregation framework; I think I need to read/view up on that). https://learn.mongodb.com/learn/course/schema-design-patterns/lesson-1-inheritance-pattern/learn?client=customer&page=2 gives the aggregation pipeline used in this lesson.
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"
},
----
Above seems to be Extended JSON. See https://www.mongodb.com/docs/drivers/java/sync/v4.3/fundamentals/data-formats/document-data-format-extended-json/,
Aggregation Pipeline, https://www.mongodb.com/docs/manual/core/aggregation-pipeline/ has some simple examples and also explains field paths which use $ symbol.
Aggregation Stages, https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference
Aggregation Operators, https://www.mongodb.com/docs/manual/reference/operator/aggregation/#std-label-aggregation-expression-operators
=========================================
I am suspending my MongoDB tutorial learning here as something else has cropped up which I need to focus on.
Comments
Post a Comment