How MongoDB is different from a SQL database
Generally speaking there are 2 major types of databases: SQL databases, and NoSQL databases
If you are familiar with MySQL or PostgreSQL for example, SQL databases allow you to add and retrieve data using a specific language, called SQL, that looks like this:
SELECT * FROM cars
INSERT INTO cars VALUES (fiesta, 2010)
SQL is rather old, being born in 1986, and it’s a battle-tested technology.
Under the NoSQL umbrella we put all those databases that do not use the SQL language for querying the data.
MongoDB falls under this umbrella.
MongoDB is a document database. Instead of storing records, we store objects (called documents).
How does this differ from a SQL database? Tables in a SQL database are flat and static, they can host data but limited to what the original intent was (you can’t add a column dynamically) and to store complex data you need to create many tables and link the data in each table, following the relational databases common practices (like foreign keys, column types, etc).
In MongoDB you can store any object without having to worry about the particular fields that compose this object and how to store them. You tell MongoDB to store that object.
With MongoDB, you don’t need to learn another language to interact with the data: you just call the JavaScript methods it exposes and that’s it (of course you can interact with it using other languages as well).
Data is stored in a format similar to JSON, but enhanced to allow storing more than just basic data types.
I hope this gives you a brief overview of the key differences between SQL databases and MongoDB.
download all my books for free
- javascript handbook
- typescript handbook
- css handbook
- node.js handbook
- astro handbook
- html handbook
- next.js pages router handbook
- alpine.js handbook
- htmx handbook
- react handbook
- sql handbook
- git cheat sheet
- laravel handbook
- express handbook
- swift handbook
- go handbook
- php handbook
- python handbook
- cli handbook
- c handbook
subscribe to my newsletter to get them
Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing [email protected]. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.