Christian LSANGOLA
Christian LSANGOLA

Reputation: 3317

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

Upvotes: 4

Views: 2976

Answers (4)

Alimo
Alimo

Reputation: 197

When you have large volume of schema-less data. When your data and users are going to grow indefinitely and you need a scalable cloud database solution. When you need higher performance boost in certain aspects of your CRUD. When your software stack is JS based. You can check the other reasons in this youtube video https://youtu.be/K8xsuFgCRkU

Upvotes: 0

Jiulin Teng
Jiulin Teng

Reputation: 364

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.

Upvotes: 4

Suresh Shetiar
Suresh Shetiar

Reputation: 157

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.

Upvotes: 5

Rohit Dalal
Rohit Dalal

Reputation: 866

From my personal experience I would use SQL when the project is somewhat like a social media having to maintain Posts, Comments, likes, blocking, Unblocking. I hope u get the idea.

Mongo Db can also be used for above project type but its aggregations become pain and unreadable.

Mongo Db is good for all projects except socialmedia alike. Once again this is from my experience.

Upvotes: 1

Related Questions