MongoDB Schema Design Best Practices

Sdílet
Vložit
  • čas přidán 3. 06. 2024
  • Title: MongoDB Schema Design Best Practices
    Date of stream: 4/9/2020
    Slides: joekarlsson.dev/MongoDBSchema...
    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 talk, we 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.
    ► $100 in FREE MongoDB Atlas Credits - Sign up here and apply code JOEK100 on the billing page.
    joekarlsson.dev/free-atlas-cr...
    ► MongoDB Community
    - MongoDB University: joekarlsson.dev/MongoDBUniver...
    - MongoDB Developer Hub: joekarlsson.dev/MongoDBDeveloper
    - MongoDB Community Forums: joekarlsson.dev/MongoDBDeveloper
    ► Additional resources:
    - Modeling: university.mongodb.com/course...
    - 6 Rules of Thumb for MongoDB Schema Design: Part 1: www.mongodb.com/blog/post/6-r...
    - Data Model Design: docs.mongodb.com/manual/core/...
    - Data Model Examples and Patterns: docs.mongodb.com/manual/appli...
    - Building with Patterns: A Summary: www.mongodb.com/blog/post/bui...
    ► Subscribe:
    Joe Karlsson's CZcams channel: / joekarlsson
    ► Video archive:
    Source files: github.com/JoeKarlsson
    Follow for notifications: / joe_karlsson
    ► Follow Me
    - Twitch: / joe_karlsson
    - Twitter: / joekarlsson1
    - Website: www.joekarlsson.com
    - Instagram: / joekarlsson
  • Věda a technologie

Komentáře • 312

  • @yanmoenaing71
    @yanmoenaing71 Před 3 lety +26

    Rule No.1 is my favorite.
    => Favor embedding unless there is a compelling reason not to.

  • @alejandromedina649
    @alejandromedina649 Před 4 lety +95

    I'm new at using MongoDB and this video has solved many doubts I had about how to design the ideal schema for my project. Thank you very much!

    • @JoeKarlsson
      @JoeKarlsson  Před 4 lety +7

      This is the best thing I have ever heard - thank you!

    • @DIZZLEBOI44
      @DIZZLEBOI44 Před 3 lety +1

      @@JoeKarlsson have a mongodb/admin job coming up

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety

      @@DIZZLEBOI44 Nice!

    • @Ikilledthebanks
      @Ikilledthebanks Před 11 měsíci

      What’s the easiest way to manage streams from mongo into snowflake using Kafka. The data structure changes and the update replace does not include data elements of the prior record. We require only the most recent update to the record no history

  • @InternetLiJo
    @InternetLiJo Před 3 lety +16

    Joe you’re a great instructor. Starting with the context/use case and then referencing the parts is so appreciated. Your channel is wildly underrated. Also love the humor references.

    • @JoeKarlsson
      @JoeKarlsson  Před rokem

      Thank you so much. I really appreciate that.

  • @axelneumann8443
    @axelneumann8443 Před 3 lety +20

    Summary:
    With MongoDB you have to consider your access patterns not only for indexing but also for schema design.
    There are three options for child documents:
    1. Embedding
    2. Array of references in the parent
    3. References in the children (foreign key)

  • @khasmeenusman3931
    @khasmeenusman3931 Před 3 lety +2

    No one explains mongodb schema as you did. Thank you man. I finally understood MongoDB

  • @sarahahmed2112
    @sarahahmed2112 Před 3 lety +1

    Thank you so much for posting this presentation. I appreciate the multiple recaps throughout the lecture, helped me a lot.
    And I appreciate the many resources.

  • @epacke
    @epacke Před 3 lety +3

    Excellent presentation, it served super well as a foundation for the design discussions about our NoSQL schema. Although we went to with CouchDB all that you said felt relevant. Instant like!

  • @BHVampireLF
    @BHVampireLF Před 3 lety +5

    I didn´t wanted to watch a 1 hour video, I think is the first time I do something like this, and wow. I learned more in one hour than in 2 days readding weird written tutorials, guides and short videos. Thank you very much.

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety +1

      Oh my gosh! That's awesome! I'm so glad it was useful for you! :)

  • @karamjeetsingh7637
    @karamjeetsingh7637 Před 3 lety +5

    This was super helpful, Cleared many doubts I had. Thank you very much!

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety

      That's amazing! Thank you so much for watching! :D

  • @vaibhavrana4953
    @vaibhavrana4953 Před 3 lety

    I am new to No SQL and coming from RDBMS background. I enjoyed this session and it gave me very good idea about how to design Mondo DB.

  • @bartoszmazur5168
    @bartoszmazur5168 Před 2 lety

    Two way referencing is just a PURE GOLD!!! Now it seems obvious, but I was trying to solve similiar problem without that 2WR knowladge 🙈, and made no progress for few hours, THANKS MAN!

  • @MohamedAsfer
    @MohamedAsfer Před 4 lety +15

    WoW. Really enjoyed this session. Thanks for the effort

    • @JoeKarlsson
      @JoeKarlsson  Před 4 lety

      Thank you so much! I am so glad you enjoyed it!

  • @morapedikhutwane7405
    @morapedikhutwane7405 Před 3 lety +8

    Thanks a squillion Joe! 👊🏽
    This video is very informative, helpful and enjoyable 😊

  • @jmgomw7787
    @jmgomw7787 Před 3 lety +1

    This is a very cool, well explained and fun talk on mongodb. 100% recommeded!

  • @abdulrashid2023
    @abdulrashid2023 Před 3 lety

    One of the best video about schema design in mongoDB thanks @Joe Karlsson. I subscribed

  • @toneking972
    @toneking972 Před 4 lety +2

    Super helpful. I was on the fence with PostgreSQL and MongoDB. But this convinced me to go Mongo

    • @JoeKarlsson
      @JoeKarlsson  Před 4 lety

      This is the best feedback - thank you so much!

  • @daminirijhwani5792
    @daminirijhwani5792 Před 3 lety +1

    this one video explained more than a couple videos combined I watched before I stumbled here. :) I have subscribed.

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety

      Oh my gosh! Thank you! I'm so glad it was useful! :D

  • @muhammadalirasheed8894
    @muhammadalirasheed8894 Před 3 lety +2

    Solved all my doubts man since morning was searching for embedding design. Thanks a lot 👍

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety

      That's amazing! Thank you for sharing!

  • @compateur
    @compateur Před 3 lety +5

    I'm sorry, but this sounded like a sales pitch :) Understandable since you work for MongoDB. MongoDB has a predecessor, namely XML databases. MongoDB has a lot in common with XML databases. I used to work a lot with XML databases and my experience is that document databases are a * bad * fit for business domain models. You talked about cons and you didn't mention the most important con: update anomalies. But wait a minute. You mentioned this problem and came up with a beautiful solution: a reference. And even better, there is something like unbounded references. I would say, keep evolving and you end up with an SQL database :). In my experience, document databases are great when you store documents as is. For example when you have a message warehouse, or for logging/auditing. XML databases are also used by publishers to store books (DocBook and DITA for example), newspapers etcetera. But using a document database for your business model. That's a bad idea to my opinion. I have the experience to use a very performant XML database as the enterprise database for a company and it had very nasty legal consequences. It was just not the right fit . A relational model is far better. It is also much better to have a schema for you business domain model. I would get very nervous if a developer would store its documents without a schema. No rules, really? Is that a positive thing for your vital business data? Good luck!

    • @OfficialGOD
      @OfficialGOD Před 3 lety +1

      I'm using mongol for logging and analytics

    • @vinfern27
      @vinfern27 Před 2 lety +2

      When it says no rules. It means you define the rules that fit your business rather than let the rules define your business. you can enforce rules at the db level

  • @rallysahil
    @rallysahil Před 4 měsíci

    Thanks a bunch ! It was quite useful especially to see patterns at last.

  • @HSBTechYT
    @HSBTechYT Před 3 lety

    Discovered you from Twitter. Amazing talk Joe 🙏

  • @andrew-ni1lb
    @andrew-ni1lb Před 3 lety +1

    Dude, thanks, I have enjoyed your explanations!

  • @pedropalma3748
    @pedropalma3748 Před 3 lety

    Great presentation, loved it. Keep them coming😊

  • @nicolascondrea8068
    @nicolascondrea8068 Před 3 lety +1

    You deserve more subscribers! Flawless video, definitely learned a few gems from this one!

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety +1

      Thank you so much Nicolas - I may be biased, but I totally agree ;)

  • @AngeloMiranda1999
    @AngeloMiranda1999 Před 3 lety +2

    Great informative video to get started with NoSQL when you come from a relational DB background. Thanks!

  • @victorkingma4371
    @victorkingma4371 Před 3 měsíci

    Excelent tutorial, gave me a entire panoram of mongodb

  • @rajivraghu9857
    @rajivraghu9857 Před 2 lety +1

    Excellent Joe!! loved you presentation. Really helped me to clarify some doubts on mongo .

  • @distributed-systems
    @distributed-systems Před 3 lety +3

    12:32 Embedding
    17:10 Referencing

  • @extremespartan117
    @extremespartan117 Před 3 lety +2

    Fantastic and straightforward presentation! Thank you sir!

  • @harujei24
    @harujei24 Před 3 lety +1

    Thank you so much! I finally understand how to design my Schema. I subscribed.

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety

      YAY! That's the best - thank you so much!

  • @joseluissanchezortiz3599

    Thanks friend. You explain very good. from colombian, Im speak spanish and I dont have seen any video so well explained in Spanish

  • @here2thrive
    @here2thrive Před 2 lety

    1:20 -- Already I see you are a genius. Well done with this idea.

  • @prajunathunt
    @prajunathunt Před 2 lety +1

    The revisions at the end was helpful. Thank you

  • @louierichardson123
    @louierichardson123 Před 2 lety +1

    I am creating a bug tracker web app and this has answered my questions about how I should structure my many to many relationship, so thank you!

    • @JoeKarlsson
      @JoeKarlsson  Před 2 lety

      That's so cool! Can you send me the code? I would love to check out what you're working on!

  • @attilathehun1561
    @attilathehun1561 Před 3 lety +3

    Nice Video , Every thing is crystal clear
    you saved my lots of time , i am new to mongoDB from MySql background keep it up.

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety

      This is the best compliment! Thank you so much!

  • @dgillies5420
    @dgillies5420 Před 2 měsíci

    Love the 1960's-1970's Campagnolo Record bicycle de-exploding at around 25:20 into the video!

  • @t_kien
    @t_kien Před 3 lety

    I'm newbie and I found this video is amazing, now I can do it.

  • @tgerambio
    @tgerambio Před 11 měsíci

    This is beautifully explained. Thank you sir!

  • @xKenshin13
    @xKenshin13 Před 2 lety +1

    Actually quite helpful. Answered most of my questions. Thank you :)

    • @JoeKarlsson
      @JoeKarlsson  Před 2 lety +1

      That's awesome! So glad it clicked with you!

  • @ardalanhadizadeh1799
    @ardalanhadizadeh1799 Před 3 lety +1

    what i learned after just this single video was 10x times more than a 200pgs doc i read. thank you

  • @soumabratabhattacharya3375

    Awesome tutorial. Thank you very much!

  • @DaDa-gr7cy
    @DaDa-gr7cy Před 3 lety +1

    Great video, these intermediate videos are what youtube is lacking

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety +2

      Right? I feel the same way - lots of beginner level content, but not much for people beyond that. So glad you enjoyed this video!

  • @splendorman7922
    @splendorman7922 Před 3 lety

    better than official mongodb videos and tutorials.. thanks!

  • @arthurgontijo1
    @arthurgontijo1 Před 3 lety +1

    Thank you! Great content, it helped me a lot

  • @andreornelas
    @andreornelas Před 3 lety +1

    Really enjoyed your video. Was kinda funny when you said MongoDB has no Rules but then we have a section with Rules. hehe. Altough they are very helpful to keep in mind. Thanks for the great content!

  • @josemurillo4728
    @josemurillo4728 Před rokem +1

    Just one! Love that part. Great vid thanks!

  • @fernandoventilari839
    @fernandoventilari839 Před 2 lety +1

    You really saved me. Thanks a lot!!! Subscribed

  • @anuragtiwari3032
    @anuragtiwari3032 Před 3 lety +1

    Thnx a lot man , this answered so many of my doubts. Deserves 10 million views, but we all know the world 😉

  • @spacemanjack777
    @spacemanjack777 Před 2 lety +1

    Thanks for a good video.
    Coming from many years with SQL I can clearly see some benefits with NoSQL. The main selling point for me is the loose data structure of the individual documents as well as query speed when everything you need is embedded in a single document. This is where NoSQL really shines over SQL
    Maybe I'm wrong, but I get the feeling that in most cases we still need traditional SQL-like relationship references between decoupled documents and quickly we end up with something that looks an awful lot like good old SQL.

  • @joaquindelprado133
    @joaquindelprado133 Před 4 lety +4

    this is a really nice video!! thanks a lot for sharing your knowledge it's help me a lot

    • @JoeKarlsson
      @JoeKarlsson  Před 4 lety

      Yay! Thank you so much! I'm so glad that it's useful :D

  • @PuzzlingQuestions
    @PuzzlingQuestions Před 3 lety +3

    This was really good. One thing that made me laugh is in the begining you stressed that there are no rules and then later you have "Rule 1: favour embedding" haha I just thought that was funny. Thanks for the presentation, it was helpful!

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety +1

      LOL - you're totally right. I totally missed the irony! hahaha! :D

  • @omadoyeabraham219
    @omadoyeabraham219 Před rokem

    Absolutely amazing explanation 👌

  • @edwardmike7523
    @edwardmike7523 Před rokem

    Thanks for the explanations, very clear .☺

  • @harrisfpv
    @harrisfpv Před 3 lety +1

    That was great content!!! Answered many questions.

  • @gurmukhsingh2026
    @gurmukhsingh2026 Před rokem +1

    This is the best into for MongoDB. thanks a lot!

  • @dwhlab5436
    @dwhlab5436 Před 4 měsíci

    Such a amazing video .. many thanks .. great work.. cheers :)

  • @Cons2911
    @Cons2911 Před 5 měsíci

    I’m early into the video but I just want to say thank you. I’m new to this, so I’m trying to understand esp coming from relational

  • @biomedicaltechworld-btw8447

    Thanks for making such a comprehensive video for us. Stay Blessed.

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety +1

      I got you! 🥰

    • @biomedicaltechworld-btw8447
      @biomedicaltechworld-btw8447 Před 3 lety

      @@JoeKarlsson started watching MongoDB University course after this video.
      Your company must be proud of you. 👌🧡

  • @gompro
    @gompro Před 4 lety +2

    Thank you for bringing up a really cool video!

  • @sayitlikeitis1202
    @sayitlikeitis1202 Před 3 lety +1

    Very well explained .. Joe. Super presentation .. Thanks much !!

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety

      You are so welcome - I am so glad it helped!

  • @siddharthskumar6831
    @siddharthskumar6831 Před 3 lety +1

    Most underrated talks..awesome...👏👏👏👏

  • @mahendranath2504
    @mahendranath2504 Před 3 lety

    this is a lot of clear content on how to schema our mongo, I have been checking about this topic for a long, but I have a question , in SQL we have partials if DB is big or sharding , do we have such thing here

  • @YoloMonstaaa
    @YoloMonstaaa Před 3 lety +2

    You're an amazing teacher. Thank you.

  • @haishuyao4834
    @haishuyao4834 Před 3 lety +1

    Really helps doing my course project and many thannnnnnks!

  • @andresbonilla475
    @andresbonilla475 Před 3 lety +1

    one of the best explanations, thanks from Bolivia :D

  • @arrafiialfa4609
    @arrafiialfa4609 Před 3 lety +1

    hi I got a question would it be better to keep reference on both document in one to many scenario or would it be better to just keep the reference on the one document that holds many docs ?

  • @ebinxavier8589
    @ebinxavier8589 Před 3 lety

    Well explained.. easy to understand ✌️

  • @Adam-uu8dc
    @Adam-uu8dc Před 2 lety +1

    Love the office meme. Great tutorial!

  • @premprakash7981
    @premprakash7981 Před 3 lety +1

    Awesome Explanation. You have nailed it

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety

      Thank you so much! Glad you enjoyed it!

  • @juancruzstingo
    @juancruzstingo Před 3 lety

    Joe, I have a small question, how should I handle updates in the twitter example if one of the followers changes his name? Thanks and the video was really helpful!

  • @saibabaalapati8446
    @saibabaalapati8446 Před 3 lety +1

    I'm relieved bro this is best and helpful very much thanks ....

  • @davidtorres5012
    @davidtorres5012 Před 3 lety +1

    Awesome! Great explanation

  • @quasarkid4256
    @quasarkid4256 Před 2 lety

    I’m really glad I watched this video thanks a lot

  • @makari1506
    @makari1506 Před 11 měsíci

    Hi Mr.Joe,
    Great video and I learnt a lot.
    I was wondering whether you’ll be able to clear a doubt I have.
    In my project, users and tasks collections. I would like to save who created a task in a “createdBy” field. It’s always gonna be one value and would be selected every time one or multiple tasks are fetched.
    According to this video, I should embed essential data such as (userId and name) that my application would display. But I want to “refer” the user data so that fields such as name are fetched correctly. I worry if I embed the name and user updates their name, it could become costly to update in all the embeds.
    May I know what your approach would be?
    Thanks

  • @ukrolelo
    @ukrolelo Před 3 lety

    Thank you,very explanatory!

  • @lazareric
    @lazareric Před rokem +1

    I love you man, not many people talking about mongo, with proper knowledge of it. Good on you.
    An interesting question maybe, client wanted an architecture where each A collection item has many B collection items attached to it by reference, BUT querying A collection requires searching based on B collection items' properties, it was super slow, whenever I queried (50m+ documents), a collection based on properties of a different collection (so match, lookup, and the match on the lookuped documents), the query was super slow. The weird part is lookup was relatively fast even, but than the match on the lookedup documents' properties was weirdly very, very slow, any ideas why that happen? It's weird as I imagine once lookup is done, each document gets that embedded and then goes into the next stage (match) in this case, so why was match so slow, as it was supposed to match based on the already available properties embedded in the document in that stage with data in the stage (or maybe I don't understand, and it doesn't really work like that what I explained), it didn't have to use an index or do a collection scan, literally just filter documents in the stage, that's the only mind boggling thing in mongo that i don't get, everything else I love

  • @_dontlookup_4774
    @_dontlookup_4774 Před 3 lety +1

    Great video! I learned a lot, thank you!

  • @ashantharindu8915
    @ashantharindu8915 Před 3 lety +1

    Mongodb scheme design is well explained. Thank you very much.

  • @umeshwar21
    @umeshwar21 Před 3 lety +1

    great , I found it is very help full video to start project with schema design

  • @arunkutz
    @arunkutz Před 3 lety +1

    Very Informative . Thank you for this video.

  • @aniketsao
    @aniketsao Před 3 lety +1

    Awesome video. thanks for creating and sharing it. I'm new to the NoSQL databases, is there a way to test the performance of embedding vs referencing ? given the unknowns of how an application would evolve, its hard to stick to one design. have you encountered any scenarios where over time the design needed to be changed from embedded to referencing.

    • @JoeKarlsson
      @JoeKarlsson  Před 3 lety +1

      The best way to determine which schema is "best" is to run experiments by running queries with different schemas and using the built-in MongoDB Performance Advisor to determine which one is fastest.
      And yes, I have seen people needing to shift schema's overtime all the time. It's really common for web apps to have features and requirements shift over time. So, an old schema that worked great, no longer fits new requirements. It's not a problem to update your schema.

  • @jrnoh
    @jrnoh Před 7 měsíci

    Thanks man great video !!

  • @scienceblossom6197
    @scienceblossom6197 Před rokem

    I really enjoyed the it Joe! I just want to ask one thing, for one rule you said arrays should not grow without bound, and then in the example, it was just that! The two-way referencing in the task management app example where both users have an array of references of tasks, and tasks have an array of references to the users. So this has no bound... maybe by "without bound" you meant "extremely large"?!
    Thank you so much again!!!

  • @redalaraf5211
    @redalaraf5211 Před 3 lety +1

    Thnx bro, real GOAT 👊🏼🤙🏼

  • @laurencedale3854
    @laurencedale3854 Před 3 lety

    This is awesome. Perfect education to meme ratio!

  • @ajaypratapsingh2222
    @ajaypratapsingh2222 Před 3 lety +1

    Very well explained

  • @SunilPatil-hs8wd
    @SunilPatil-hs8wd Před 3 lety +1

    Thanks a lot for awesome content. Subscribed to your channel

  • @johnlloydg.trinidad8267
    @johnlloydg.trinidad8267 Před 4 lety +2

    this is gold! thank you so much!

    • @JoeKarlsson
      @JoeKarlsson  Před 4 lety

      Oh my gosh! Thank you so much! So glad you enjoyed it!

  • @ayushkushwaha171
    @ayushkushwaha171 Před 4 lety +2

    Thanks for the video Joe

    • @JoeKarlsson
      @JoeKarlsson  Před 4 lety +1

      Oh my gosh! I am so glad you enjoyed it!

  • @anudeepananth
    @anudeepananth Před 3 lety

    Alright the information shared here is gold....

  • @OfferoC
    @OfferoC Před 3 lety +1

    excellent overview thank you

  • @knightx9405
    @knightx9405 Před 2 lety

    you are simply the BEST BEST BEST bru!!

  • @code2287
    @code2287 Před rokem

    Nice resource.....could we get a complete mongodb schema playlist

  • @gmendozamb
    @gmendozamb Před 3 lety

    So if I get it well, if there are too manies and can be updated you must reference instead of embedding right ?
    SQL background sorry :P

  • @rickvian
    @rickvian Před 2 lety

    at 40:35 the "timestamp" value has $date and $numberLong, what does that mean? is that variable? or function of mongodb?

  • @hoquang6033
    @hoquang6033 Před 3 lety

    super useful! Thank you man

  • @peaps
    @peaps Před 2 lety +1

    Does referencing have to use the complicated BSON _id property? Can't we just use another normal property, like, name (presuming it to be unique) ?

  • @princematthew2145
    @princematthew2145 Před 2 lety +1

    Fantastic Joe. Great Learning. When you talk about embedding example regarding product and parts, you favor parts. But you keep referencing to the size limit of the document. Yes its a problem, But more than that there is a bigger problem of consistency. If you embed a part and If you update the part from a screen, you have inconsistency. When you show the product you will show the old values. I am curious as to why you are not mentioning about inconsistency? I am a newbie in nosql. heavily influence by relational theory. Eager to know your thoughts

  • @ranylfoumbi4641
    @ranylfoumbi4641 Před 3 lety +5

    great!
    courage bro!
    it has solved many of my doubts

  • @yogeshchaudhary621
    @yogeshchaudhary621 Před rokem

    Great tutorial indeed.