Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should i use mongoDB instead of a relationnal database

I've followed several courses on udemy about NodeJS/Express,ReactJS/Redux and some the courses are MERN STACK and i've really enjoyed them.But the only thing that instructors don't really explain is the choice of MongoDB.Before taking theses courses i always use whether PostgreSQL or MariaBD for all my projects persistence layer.And now i've just used MongoBD in all theses courses without knowing in what kind of situations it's the best choice or not.All the instructors just say that as data are stored like json json arrays,it's easy to parse as it's naturaly compatible with Javascript just like any JSON format.I would really like to understand technical reasons of using Mongo instead of relationnal database or not according to any given project requirements instead of just using it because instructor do so

like image 864
Christian Lisangola Avatar asked Oct 16 '25 17:10

Christian Lisangola


2 Answers

I have worked in both SQL and MongoDB.

MongoDB

From my experience MongoDB is best suitable when you follow agile methodologies 
wherein you don't really know what your JSON object will have to contain.

SQL

SQL will be best suitable where JSON object is not going to be changed, like 
for bank projects, where you know the exact format of JSON which is never going 
to be changed.

DIFF

Why I am saying this is, whenever we need to add some extra fields or need to 
link some fields with primary, foreign keys it would be pain and wouldn't know 
what could go wrong.

Wherein in MongoDB if you need to reference some field you will just need to 
add key ref with that field and you are done.

MongoDB

MongoDB would be great when one of your key from one JSON object is to be 
referenced to mutiple JSON object by just adding that field name in ref (ref: 
'user')

Please vote this answer so that someone in need finds this answer and can get when MongoDB would be best suitable for them.

like image 97
Suresh Shetiar Avatar answered Oct 19 '25 12:10

Suresh Shetiar


My take is that SQL is preferred when:

  • Relational integrity (data integrity) is essential
  • Data is updated frequently
  • Clear and/or strong relations exist between entities

MongoDB is better for:

  • Horizontal scaling / sharding
  • Replicating SQL data to avoid costly queries in production (some alternatives may be better)

I would say that when unsure use SQL. It's much easier to migrate from SQL to NoSQL than the other way around when you change your mind.

like image 40
Jiulin Teng Avatar answered Oct 19 '25 12:10

Jiulin Teng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!