DEV Community

Discussion on: MongoDB vs PostgreSQL: what to consider when choosing a database

Collapse
 
elmuerte profile image
Michiel Hendriks

Schema evolves as your application evolves

That makes it sound like you cannot modify the schema in a RDBMS, which obviously you can. The main difference is that in a relational database you only have 1 schema for all your data. Adding a column means all data also gets this piece of information.

With a typical NoSQL database you need to make sure your application supports all versions of the "schema" you have stored in it. If you don't, accessing old data will not be possible without issues.

Modifying a schema in a relational database can be expensive though. Adding or removing columns is often cheap (in modern PostgreSQL adding a new column with a default value is just as cheap as adding a nullable column). But converting data requires rewriting every row.

The relational database approach requires you think about your data model, where with NoSQL you can postpone it. However, postponing thinking about the data model never works out. So even with a NoSQL approach you need to thing about your data model otherwise you will need to write, and maintain, a lot of supporting logic in your software.