MongoDB Schema Design Best Practices

Ғылым және технология

✅ Sign-up for a free cluster at: mdb.link/free-QAqK-R9HUhc
✅ Get help on our Community Forums: mdb.link/community-QAqK-R9HUhc
Have you ever wondered, “How do I model my schema for my application?” It’s one of the most common questions devs have pertaining to MongoDB. And the answer is, it depends. This is because document databases have a rich vocabulary that is capable of expressing data relationships in more nuanced ways than SQL. There are many things to consider when picking a schema. Is your app read or write-heavy? What data is frequently accessed together? What are your performance considerations? How will your data set grow and scale?
In this video, Joe Karlsson will discuss the basics of data modeling using real-world examples. You will learn common methodologies and vocabulary you can use when designing your database schema on your application.
Chapters 📑
0:00 Intro
0:18 Why is schema design important?
1:21 Relational vs. MongoDB schema design
4:16 One to One
4:41 One to many
6:10 One to Squillions
8:02 Many to Many
8:57 Wrap Up
💬 What topics do you want to see covered next? Leave a comment below!
🔗 These ARE the links you are looking for 👋:
MongoDB Schema Design Anti-Patterns - Part : • Schema Design Anti-Pat...
------
✅ Subscribe to our channel: mdb.link/subscribe

Пікірлер: 91

  • @MongoDB
    @MongoDB Жыл бұрын

    ✅ Sign-up for a free cluster at: mdb.link/free-QAqK-R9HUhc ✅ Get help on our Community Forums: mdb.link/community-QAqK-R9HUhc

  • @chauphan4074
    @chauphan40743 жыл бұрын

    Rule 1: embed unless there is a compelling reason not to Rule 2: avoid JOINS if they can be avoided Rule 3: array should never grow without bound Rule 4: an object should not be embedded if it needs to be accessed individually

  • @paracha3
    @paracha32 жыл бұрын

    Not sure if i am fan of this delivery style but he was getting the point across.

  • @joshuapapa7637

    @joshuapapa7637

    11 ай бұрын

    I gotta agree with you, I literally came here not knowing a thing and I almost feel like I can create a project out of scratch after watching this.

  • @jmanpolo5611
    @jmanpolo56112 жыл бұрын

    Coming from a SQL mindset to MongoDB is an interesting experience, but also kinda freeing in a way.. thanks for making this video!

  • @murph1329
    @murph13292 жыл бұрын

    Things people really need to consider before moving everything to MongoDB. It isn't a relational database management system. Saying MongoDB is better than any RDBMS without first specifying the data shows a real lack of knowledge. Key constraints don't exists in MongoDB. There are no referential integrity checks. We use MongoDB for blob storage and store the MongoDB keys in SQL Server. It's great for that but I would never outright replace a normalized SQL Server or a MySQL RDBMS instance with MongoDB. Maybe a lot of people see MongoDB as being better because they don't want to worry about optimizing indexes and execution plans, and they see the "read" performance gains...but that comes at a cost of data integrity. It's a schemaless structure which means consistency doesn't exist. It will eat anything you feed it which can be dangerous. Think about what happens over time as you add/remove properties from your JSON or add/remove reference data based on changing business rules. Think about what that conversion would look like in MongoDB compared to a RDBMS instance. Using the example in this video what if there was a business rule that allowed someone to remove a profession (physical or logical) from all users. Ask yourself what that would look like in MongoDB vs a Relational Database. I know I sound pretty critical of MongoDB but I don't mean to. We use it and it works well for our needs but it's not a replacement for RDBMS. More of a supplement. NoSQL shines in write-once-read-many scenarios.

  • @elonhung2430
    @elonhung24303 жыл бұрын

    Thanks Joe! That is gold. Very clear and so fun to watch!

  • @picklebrownie
    @picklebrownie Жыл бұрын

    So, for many-to-many relationships, Joe suggests to store the relationship data in BOTH tables (very unlike SQL dbs where we avoid redundancy). This helped me resolve a quarrel with myself on the db schema for my first MongoDB Atlas Collections. Thanks Joe

  • @maxpayenvenic6029
    @maxpayenvenic60292 жыл бұрын

    Joe is kind of person that make learning fun

  • @BobMacNeal
    @BobMacNeal3 жыл бұрын

    Good job explaining/confirming my loosely established notions about how to design a NoSQL database. Thanks Joe. MongoDB is a low-resistance (easy to use) database that’s become my go-to data store for standing up products.

  • @VoxyDev
    @VoxyDev3 жыл бұрын

    MongoDB needs Joe, he's so good at explaining things

  • @laodemuhammadalfatih7663
    @laodemuhammadalfatih76632 жыл бұрын

    Omg. I really love about how Joe explain the all of these schema design. Never feel exciting like this when learning new concept. Thanks Joe ❤️.

  • @jbsinluenam
    @jbsinluenam Жыл бұрын

    I have never knew MondoDb schema design can be this entertaining. Thank you, Joe.

  • @king-manu2758
    @king-manu27583 жыл бұрын

    Im a total noob at programming and Mongo db but after watching this I think I'm at least on the right track

  • @JoeKarlsson

    @JoeKarlsson

    3 жыл бұрын

    That's awesome! I'm so glad it was helpful!

  • @MongoDB

    @MongoDB

    3 жыл бұрын

    Yay! That great that it was helpful!

  • @dixxixio
    @dixxixio2 жыл бұрын

    This helps a lot! Thanks Joe!

  • @philyeo
    @philyeo3 жыл бұрын

    Great explanation. Just what I was looking for.

  • @gt810034
    @gt810034 Жыл бұрын

    Excellent explanation. Thanks Joe

  • @AnNguyen-px6lg
    @AnNguyen-px6lg2 жыл бұрын

    I love the style of this video so much. It makes learning tech so much more fun compare to other monotone tech videos.

  • @RN-er7mz
    @RN-er7mz3 жыл бұрын

    Great tutorial, short and straight to the point

  • @MongoDB

    @MongoDB

    3 жыл бұрын

    Thank you!

  • @real23lions
    @real23lions7 ай бұрын

    Excellent video. This was my main concern when attempting a scheduler.

  • @niknacknutthapon4373
    @niknacknutthapon4373 Жыл бұрын

    i'm new on your VDO, Love it ! Great tutorial. you make learning super fun

  • @sleeker165
    @sleeker165 Жыл бұрын

    Excellent demo thanks 👍

  • @davishek7
    @davishek7 Жыл бұрын

    Just read the same blog on the mongodb site. Both are great for beginners.

  • @oberoioffice1103
    @oberoioffice1103 Жыл бұрын

    Explains the conept very well...thanks

  • @zulmianah
    @zulmianah2 жыл бұрын

    thank you, really helping

  • @vaibhav388
    @vaibhav388 Жыл бұрын

    Thank you . that's what i was looking for ;)

  • @learn9475
    @learn9475 Жыл бұрын

    I can see the passion video quality is awesome upto the mark not just learnt but njyed learning from you thanks

  • @underwoodmartin
    @underwoodmartin3 жыл бұрын

    Great firehose video for those of us that have spent many many years in a relational world. I have did some entry level testing with MongoDB and love the concept. The "schema" is the most challenging part. Awesome video!

  • @JoeKarlsson

    @JoeKarlsson

    3 жыл бұрын

    Oh my gosh - Thanks for sharing Martin! Are there any topics you think MongoDB devs should know about?

  • @MongoDB

    @MongoDB

    3 жыл бұрын

    Thanks for sharing!

  • @underwoodmartin

    @underwoodmartin

    3 жыл бұрын

    @@JoeKarlsson MongoDB has always been very intriguing to me with the BSON based storage. I would love a series on taking a case study of an OLTP based system and converting to MongoDB. Highlighing the many decision and concerning aspects along the way. Thank you for inquiring and looking forward to finding time to watch more.

  • @ljbrown238
    @ljbrown2383 жыл бұрын

    VERY helpful!

  • @enemy537
    @enemy537 Жыл бұрын

    I loved your video Joe. Fantastic. You are such a character! hahaha

  • @atikanajla
    @atikanajla Жыл бұрын

    I need more video from you Joe

  • @SomeKindaWhale
    @SomeKindaWhale Жыл бұрын

    Grok! Nice 😊 thanks! This was a super informative and fun video explainer

  • @paulafarrugia3393
    @paulafarrugia33933 жыл бұрын

    Great tutorial - would be great to have a video tutorial on how to actually implement the relationship types in realm!

  • @MongoDB

    @MongoDB

    3 жыл бұрын

    Great suggestion!

  • @paulafarrugia3393

    @paulafarrugia3393

    3 жыл бұрын

    @@MongoDB Is this something that you think you will release soon? I'm having trouble with relationships when using Realm and GraphQL and noone on the MongoDB community is helping.

  • @mirlamontano6640

    @mirlamontano6640

    Жыл бұрын

    agree

  • @deathdefier45
    @deathdefier45 Жыл бұрын

    You're the best Joe, I had a filthy schema structure until I saw this video.

  • @unnoticedspacegoat8537
    @unnoticedspacegoat853711 ай бұрын

    love the energy

  • @coderblog4485
    @coderblog448511 ай бұрын

    great work Joe!. In fact, it is very interesting to watch your videos about MongoDB, but I am confused about one thing🧐🤨

  • @SaudBako
    @SaudBako3 жыл бұрын

    Isn't the array "tasks" at 8:45 unbounded, which violates Rule 3?

  • @matonolo

    @matonolo

    2 жыл бұрын

    Yeah it does, and I can't think of a way to solve the 60mb per document limit problem... Anyone know how to solve it?

  • @sjacobsen

    @sjacobsen

    2 жыл бұрын

    Just depends on the application. Technically: yes. Are users REALLY going to have an unlimited amount of todo tasks that will create document size problems: no. If you're worried about malicious activity doing this to kill your site then setup some business logic to keep a user from creating a billion tasks.

  • @pazuso
    @pazuso2 жыл бұрын

    My app shows a profile page of a student with a list of classes she's enrolled in. Classic Student/Class/Enrolment tables in SQL. In Mongo I would want to just embed everything in 1 document. What if I change the name of a class, or a student drops a class previously enrolled? How do I do this WITHOUT joins? "Throw away" the document (delete) and just make a new one (like a piece of physical paper) with the updated stuff?

  • @BelieveInPeople121
    @BelieveInPeople121 Жыл бұрын

    is joins in mongodb slower than sql server? because if I use objectids, I will always need joins.

  • @zedrem9876543210
    @zedrem98765432102 жыл бұрын

    What's the best way to model a one to many relationship within a single collection. E.g. users following users? I always use a followers array on the user document that stores other user IDs, but it feels clanky (unbounded array?)

  • @hope-ag

    @hope-ag

    2 жыл бұрын

    This scenario resembles a many-to-many relationship (each user can follow and be followed by many users, if I'm not mistaken). Depending on the scale of the application, an array of sub documents would do just fine. For larger applications, you could probably have a "Followings" collection, which stores, for example {user: $oid, followedBy: $oid}. This collection can easily be queried for whichever user's followers you'd want to find

  • @labydamarocamara5874
    @labydamarocamara58743 жыл бұрын

    thank you for this video it is so amazing, really I like it.

  • @MongoDB

    @MongoDB

    3 жыл бұрын

    We're so glad that you enjoyed it!

  • @sneakykk
    @sneakykk Жыл бұрын

    he is so full of energy. bless him!!!

  • @fernandonogueira2291
    @fernandonogueira22917 ай бұрын

    This video is absolutely histerical! haha Amazing, Mongo!

  • @picklebrownie
    @picklebrownie Жыл бұрын

    Oh wow, super clever way to handle squillions of data relationships 💯

  • @codingcambodia
    @codingcambodia2 жыл бұрын

    I have a collection called "hospitalization" that stores two collections ids a hospital_Id and a patient_Id. My question is I want to query hospitalization collection and search by keyword of field of hospital collection of hospital collection. how can I do so?

  • @jdragon8184
    @jdragon81842 жыл бұрын

    Can anyone please please help me with how can I make combination of 2 field values unique , should i use a pre save or method to implement it or mongo has something for it 1 i want to have unique anime name for a particular user , so i use a createdBY userid to identify it but I cannt make anime title unique

  • @sumer420
    @sumer4203 жыл бұрын

    iam new to mongodb .and i want to know how what is best practices and what is not best but optimum for my needs 1) get all the data and sort and filter client side (i know this is bad) 2) filter data on mongo atlas and then sort client side (dose it make any difference to save resource on server ) 3) filter and sort on server and just show data on client what should i do and what are best practices. like i get a list of documents from server with embedded objects. 1) should i use project and remove embedded objects i dont need.( does this use more server resource) 2) or i get all the embedded objects and hide them with client side logic

  • @dubey_ji
    @dubey_ji Жыл бұрын

    okay that Pam's bit was funny

  • @Dannyboyjr
    @Dannyboyjr Жыл бұрын

    dude is awesome

  • @funksoul123456
    @funksoul1234563 жыл бұрын

    Thank you for sharing. Would you also provide the link for anti-pattern design?

  • @MongoDB

    @MongoDB

    3 жыл бұрын

    Of course! kzread.info/dash/bejne/aneO1Y9pmdefopc.html

  • @DarkzarichV2
    @DarkzarichV26 ай бұрын

    I don't quite get why with many-to-many relationship we store tasks within user model as the rule way when we can technically query tasks that $in a user we want to get. It would also make updates\deletes harder because now if we have to remove a task we need to delete elements in both arrays: user.tasks array and owners array of the task. I'm not saying it's bad per se it really depends on what app we have: having tasks inside user model would certainly make it faster for users to see what tasks they got. Anyway if I remember correctly this is what is called denormalization: we introduce a bit overhead in the data to make updating and removing slower but reading faster in certain particular cases. Denormalization is a bit harder than just "do like this" thing

  • @rohannnsingh84
    @rohannnsingh843 жыл бұрын

    That's what i waz looking as i am strtng to swtch from sql to mongo but after viewing this i have a ques ...what if data is in millions or in tonnes let suppose the user has 10k cars just assume then what happens?? What about efficiency then , will it work as same speed ????

  • @MongoDB

    @MongoDB

    3 жыл бұрын

    Well - it depends. The only way to know is to run a test on your dataset to see how well it will perform. However, it's not an anti-pattern to do this in MongoDB. Another question to ask is "How often will this be done?" If it's rare, it's usually not an issue, if it's often, you might want to change your schema. The only thing that matters is designing a schema that meets the needs of your unique application. Hope that helps!

  • @dancruz7845
    @dancruz784511 ай бұрын

    If an array can not grow without bound how to we manage something like a users posts? We obviously wouldn't want to limit a users posts so how do you work around that?

  • @williamhorn363

    @williamhorn363

    6 ай бұрын

    I'm guessing you would just create a new document containing the post data, and attach the user's ID somewhere in there. Then you just query posts for a user id whenever you want to retrieve all posts from a user.

  • @kevinandeleven
    @kevinandeleven3 жыл бұрын

    What of squilions to squilions relationships? Something like users and post-likes.... A user can like a squilion posts and a post can have a squilion users that like it

  • @snake3837

    @snake3837

    3 жыл бұрын

    Maybe just 3rd collection containing user and post id.

  • @magellan124
    @magellan124 Жыл бұрын

    What is going on with that painting back there?

  • @juanbovier7458
    @juanbovier7458 Жыл бұрын

    💯

  • @michaelshea4834
    @michaelshea48342 жыл бұрын

    I am not sure why, but for some reason it looks like you are filming inside a bar before it opens. Weird.

  • @jungtinnumbertwo4323
    @jungtinnumbertwo43232 жыл бұрын

    Love the content

  • @liquidcode1704
    @liquidcode1704 Жыл бұрын

    SQL => business/enterprise 'storage' MongoDB => application state !!! =]

  • @picklebrownie
    @picklebrownie Жыл бұрын

    NO RULES 🤯 NO ALGORITHM 🤯 NO PROCESS 🤯

  • @picklebrownie

    @picklebrownie

    Жыл бұрын

    Woohoo! There are rules! It's not total anarchy 😂

  • @krishnandusarkar
    @krishnandusarkar3 жыл бұрын

    Thanks for the explanation. Honestly, too much transition effects and fast speaking actually affecting the concentration.

  • @MongoDB

    @MongoDB

    3 жыл бұрын

    Sorry to hear that! Thanks for watching 🥰

  • @derkin860
    @derkin8603 жыл бұрын

    w00t

  • @MongoDB

    @MongoDB

    3 жыл бұрын

    w00t!

  • @ZalexMusic
    @ZalexMusic2 жыл бұрын

    You are extremely likeable

  • @dataisbeauty5512
    @dataisbeauty55123 жыл бұрын

    1 st comments

  • @MongoDB

    @MongoDB

    3 жыл бұрын

    Nice!

  • @MultiMunding
    @MultiMunding7 ай бұрын

    Yeah but what about many to squillions or squillions to squillions? Back to joins? 😆

  • @moosegoose1282
    @moosegoose1282 Жыл бұрын

    Unwatchable. Just get to the point.

  • @picklebrownie
    @picklebrownie Жыл бұрын

    One to squillions 😂

  • @picklebrownie

    @picklebrownie

    Жыл бұрын

    Squillions is an unspecified massive number. I for real thought you made it up for a moment there 😂

  • @tobbymarchal3140
    @tobbymarchal31408 ай бұрын

    I hate this background music I don’t why😂

  • @TheNamesJT
    @TheNamesJT2 жыл бұрын

    I don't find this video helpful sorry, wish you would of shown actual code using schema and models and how to connect two schemas together. This video is just saying we have to do this and do that but you never show us code wise. VERY HELPFUL

Келесі