SQL vs NoSQL - An Intro to MongoDB
This brief lesson highlights some of the differences between relational and non-relational databases, and introduces MongoDB.
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo 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.
This lesson preview is part of the TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL course and can be unlocked immediately with a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL with a single-time purchase.
[00:00 - 00:17] 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.
[00:18 - 00:33] 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.
[00:34 - 00:45] 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.
[00:46 - 00:59] 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.
[01:00 - 01:15] 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.
[01:16 - 01:29] 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.
[01:30 - 01:42] 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.
[01:43 - 02:01] 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.
[02:02 - 02:16] 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.
[02:17 - 02:34] 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.
[02:35 - 02:50] 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.
[02:51 - 03:00] Examples could be MLAB, Object Rocket, Atlas, etc. There are a few advantages to using a database as a service.
[03:01 - 03:15] 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.
[03:16 - 03:26] 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.
[03:27 - 03:42] 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.