7
tahnik
6y

Has anyone here used MongoDB for relational databases? I am trying to use MySQL with Node but I feel like the whole thing is a mess. There are some ORMs like Knex or Sequelize for MySQL but they are pretty crap. I am thinking if I should just move onto MongoDB instead of MySQL, at the same time I feel a little dirty to store relational data in a document store :(

Comments
  • 2
    NoSQL doesn't really do relational. It's like FB graph. All data is stored in documents.

    There will be data duplication. You can do joins but that would be in the app layer: It would query the 2 collections and join and create a new document joining them.

    Usually that's not good performance wise for large quieries so when you load the data you basically put everything u ever need about that object into it.
  • 2
    @billgates the problems I see is that the code for MySQL is huge compared to Mongo. I have so much code just to deal with simple tables that it is annoying me a lot.
  • 3
    "I am trying to use MySQL with Node"

    mysql2 npmjs
  • 1
    @tahnik welcome to my world. I'm not really sure how you are getting it but I guess the first step is creating the collections needed in mongo.

    If you can stick with MySQL and don't want to redesign the data models, go with what Josh said.

    If you want/need mongo, you can start with splitting and recreating and I guess if performance is a noticable problem then add whatever takes the longest into the FROM collection.

    That's sorta what we do...

    1.Manual join
    2. Optimize queries
    3. Preload the data as a child node

    Maybe take a look at a mongo DB cookbook.

    But really needs to be case by case I think.
  • 1
    @JoshBent lol!

    @billgates yeah, I moved onto Mongo. My use case probably has a better fit with SQL but it has way too much overhead. And for a one man team, I can't be bothered to maintain it.
  • 1
    @tahnik overhead == monkey developers that write junk code and think PCs have infinite speed so performance ain't a problem as long as the right result returns eventually?
  • 1
    @billgates more like writing 1000 lines of code for hello world lol.
  • 2
    @tahnik will if those 1000 lines can new amortized and save you from writing 10,000 it's not too bad.
  • 0
    @tahnik well tbh, I have never reached for an ORM in node, it's just ugly and unreadable imho, especially in comparison with e.g. eloquent in laravel.
  • 0
    @JoshBent mongoose is just beautiful. All the sql ORMs are absolutely rubbish.
  • 0
    @tahnik looks almost as ugly to me, just a bit less, also abusing mongodb for anything else but its purpose, will end up in a lot of unmaintainable and self destructive chaos (especially with all hacks, to make it somewhat behave like mysql)

    not to mention if you do want to scale at some point, how much pain comes with it, versus maintaining mysql

    Just an interesting read on topic:
    http://cryto.net/~joepie91/blog/...
  • 1
    @JoshBent I have read those blogs and more. Most of them are outdated. MongoDB recently passed the Jepsen test: https://mongodb.com/mongodb-3.4-pas....

    So I don't think it's as bad as it used to be.

    And as for the DB design, you generally don't design NoSQL to behave like SQL. It has it's own design pattern. The docs of firebase is quite helpful to learn those.
  • 0
    @tahnik I would really hope they improved since, though I still hear horror stories about it, so I rather pass on using it in production, especially any bigger scale than a hobby project.

    Also you did make it sound, like you would want to make mongodb (dbms) work like mysql (rdbms), which still, will imho result in unmaintainable mess.
  • 1
    @JoshBent I am trying to follow the design guidelines of NoSQL. Hopefully it won't be a mess.
  • 1
    "MongoDB for relational databases"... Say this again, but slowly
  • 0
    Is postgres out of the question
  • 0
    SQL works fine with node. Are you using a bad plugin?
  • 0
    @marcorodnav lol

    @inaba @hashedram the problem for me is the amount of code to maintain for SQL. There is too many layers of validation for simple stuff. For example, with MySQL, I need migrations for the tables, then I need models for each table, I need controllers as well.

    With Mongo, I can just have models with proper validation rules and it's perfect as long as the design is done correctly. What's even better is because I am using GraphQL, I can just fetch data directly from Mongo and pass it to the GraphQL, which automatically filters out unnecessary data.
Add Comment