Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why NodeJs usually use MongoDB not Mysql?

Tags:

node.js

I heard about Mysql used big companies like Uber, Linkedin. I think NodeJs is best to use Mysql than MongoDB. Am I wrong? Maybe i don't know features about MongoDB

like image 409
Otgonbayar Lamjav Avatar asked Feb 05 '23 03:02

Otgonbayar Lamjav


1 Answers

Like you I was in the same dilemma when I started learning NoSQL. Coming from a RDBMS background NoSQL or MongoDB is easier to scale and has a JSON-like syntax that feels home with JavaScript developers. Imagine this structure when you were developing a Todo app:

Todo Database (MySQL):
- Todo (table)
  - Id

- Todo Item (table)
  - TodoId
  - TodoName

With MongoDB you can put everything in one Table or Collection like so:

Todo: {
  Id: //some uniq id,
  Items: [
    0: {
      name: 'wash the dishes'
    },
    1: // and so on
  ]
}

And later on if you decide to break or add more details you can do so, hence the word "scale"

Todo: {
  Id: asdf
}

TodoItem: {
  todoId: asdf,
  name: 'wash the dishes',
  etc: // and so on
}

And best of all if you feel you're app is almost set in stone, you can transfer to MySql or Postgresql which the big companies you mentioned are doing.

This is just an easy example and probably using NoSql over Sql won't be that much of a benefit. But think of this, you are trying to build out a new app with unfamiliar data relationships. Yes, you can build ER Diagrams and normalize it as much as you want and when you start building your app you realized one very important field which might affect the entire relationships of your tables. OR would you rather build fast and get your hands dirty, build messy tables/collections with NoSql and see your app come alive much quicker?

Hope that helps.

like image 112
JohnnyQ Avatar answered Feb 08 '23 10:02

JohnnyQ