• Rayquetzalcoatl@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    3 days ago

    I’m currently building something using Mongo as the DB, and have so far been making sure to assign the user ID to everything that relates to that user when it’s created.

    Wouldn’t you have to do something like that in MySQL anyway to ensure that the entries related to each other?

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      1
      ·
      23 hours ago

      Oh yeah, I’m saying that relational databases push you even more to assign IDs to every miniscule piece of information, especially if you’re following best practices (3NF or similar).

      For example, you’re not supposed to say that a user has a list of interests, you’re supposed to say that there’s users with a user_id and then there’s user_interests with a user_id and an interest_description, so two separate tables.
      If those interests can be indexed, then you’d want three tables:

      • users(user_id)
      • interests(interest_id, description)
      • user_interests(user_id, interest_id) (N-M-Mapping)

      I mean, this might not be the best example, as it kind of makes sense to not always load the user interests whenever you do anything with the user, but yeah, the point is that you’re supposed to split it up into separate tables and then JOIN it as you need it.

      With these RDBMS, your entire data loading logic is supposed to happen in-database, so you pretty much need to chop the data into the smallest possible parts and assign IDs to all of those parts, to give you the flexibility to access them how you need to.

      • Rayquetzalcoatl@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        17 hours ago

        Ahhh okay I see. I’ve developed sites for a decade but have never had to really consider how databases work in any great detail, which obviously now with mongo I am having to think about. Thank you for clarifying! I’ve got some reading to do 🫡