MongoDB
Adding persistence to application means storing data so that it persists beyond the lifetime of the application.
The easiest way to achieve this is perhaps to save data to (plain text) files. For simple applications, it is fine to persist data directly to disk as text files. However, when building larger applications, in particular for use by many users, file-based persistence can cause problems:
- sharing can cause data loss or lead to security problems
- having multiple files can result in data redundancy and inconsistency
- querying files is difficult in particular in case of concurrent access
The solution is to use a database (together with a Database Management System).
A database is a shared collection of related data.
Database Management Systems (DBMS) provide a convenient environment to create, secure and maintain databases.
DBMS provides an API for users to (efficiently) retrieve and store information from/to database.
We will be using a database and DBMS application called MongoDB.
MongoDB is a cross-platform document-oriented database program.
MongoDB uses JSON-like documents with optional schemas. It plays well with JavaScript and Node applications. Its simplicity (compared to traditional relational databases) speeds up application development and reduces the complexity of deployments.
You can run MongoDB locally or in the cloud. When you deploy your application you will need a cloud database. The developers of MongoDB have created an online application called MongoDB Atlas, or simply Atlas, that assists you with handling the complexity of deploying and managing your MongoDB instance on popular cloud service provides such as AWS, Google, and Azure.
We are going to work with MongoDB Atlas to provision a cloud database which we will use on our local computer as well as when our application is deployed.
The source code for the completed demo app (which we will build in this module) can be found at this link.