SQL vs NoSQL - An Intro to MongoDB

This brief lesson highlights some of the differences between relational and non-relational databases, and introduces MongoDB.

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

Table of Contents

This lesson preview is part of the TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL

When it comes to deciding on a database, one of the bigger questions that often needs to be answered is either using a relational database or a non-relational database. Relational databases are often recognized as SQL databases while non-relational databases are often recognized as no-SQL databases. SQL databases use a structured query language for manipulating and reading data which are stored in tables. As rows and columns with predefined relationships between them, hence the term a relational database. SQL databases require us to use defined schemas to determine the data structure . The advantage of this is we can always be confident in the structure of our data. However, this also means that a significant change in schema later would be difficult to manage and somewhat disruptive since earlier forms of data may or may not be used. However, this does not mean code would just magically work. Because of this flexibility, additional checks are needed in our code to determine the data that we can use in our data. The advantage of this is we can easily change our data structure as our app evolves. However, this does not mean code would just magically work. Because of this flexibility, additional checks are needed in our code to ensure our app logic can handle data with different changing structure. SQL is a good choice for any app that will benefit from a well-defined data structure. No SQL on the other hand is a good choice for any app that may have a rapid changing data structures. Basically, if we cannot define a schema for our database or if our schema is expected to change, often the case with high competition, mobile and web apps, no SQL may be a good choice. Now, this is a very high level difference between relational and non-relational databases. A lot of other topics can also be compared such as scalability, compatibility with certain languages, speed, performance, etc. We're definitely not stating one approach is better than the other because it really comes down to a lot of these different factors. With that said, however, we've decided to use a no SQL database for our course known as MongoDB. One primary reason as to why we use MongoDB is because Mongo is incredibly easy to use and implement to begin persisting data within an application. MongoDB is a no SQL database system that stores data in JSON-like documents. We can integrate Mongo to an app by installing it locally in our computer or using a database as a service platform. Examples could be MLAB, Object Rocket, Atlas, etc. There are a few advantages to using a database as a service. Maintenance and management of the database infrastructure becomes the responsibility of the service provider. Out of the box security setup is often provided, such as the capability of whit elisting certain IP addresses to access the database. Scalability and high availability is something that often comes with database as a service. As our app grows, we can reconfigure our cloud database with more processing power. With that said, in the next lesson, we're going to use the official Mongo cloud database as a service known as MongoDB Atlas. We're going to create our very first cluster followed by our very first Mongo database. [BLANK_AUDIO]