We all know how fun and efficient it can be to work on an Apple computer where you can prototype graphical interfaces, do data analysis, develop web applications, and even run database servers with your own equipment.
However, Apple can often surprise us with their OS updates that make programming a bit more challenging, such as the arrival of Catalina macOS. This update has changed how we work, since we can no longer write commands into our terminal that directly affect the root directory (/).
In this post, we will teach you how to install MongoDB on Catalina macOS so that you can continue working efficiently with your Apple computer.
Relational & Non-relational Databases
Before we get right to the good stuff, however, let’s first review the important differences between relational and non-relational databases and what it means for our work with MongoDB.
As you know, databases are the cornerstone of all technology platforms. While we’ve been working with relational databases (SQL) for a while, non-relational databases (NoSQL) are a relatively new development that took the world of technology by surprise and are here to stay. Why? Well, we can say that non-relational databases (when directly compared to relational databases) are less redundant, much lighter, and much faster.
For relational databases, we use SQL (Structured Query Language), which is a query language used to get the information we need from the database. It is a simple language to learn and feels similar to programming; it is, however, not programming.
For non-relational databases, we use the most popular programming language today, JavaScript, and the data is structured in JSON (JavaScript Object Notation), which is not a query language, but a way of structuring the data so that any program can understand it.
Examples include:
Relationals (SQL)
Non-relationals (NoSQL)
MySQL
PostgreSQL
Oracle
MongoDB
Redis
CouchDB
What is MongoDB?
MongoDB is a database that belongs to a group of NoSQL, or non-relational, databases. In MongoDB, each record is stored in a JSON document which is composed of fields that are grouped in collections.
MongoDB can be used for any application or platform that needs to store semi-structured data. It is very useful when we are looking for scalability in our projects, as it allows us to grow horizontally without problems.
Looking for a couple of reasons why you should be using MongoDB in your projects? We’ve got you covered.
Data modeling
If you use NodeJS as your backend, you are most likely using a MEAN (Mongo Express Angular Node.js) or MERN (Mongo Express React Node.js) architecture. And if you're not using JavaScript for your projects, don't worry! With the right drivers, you can use MongoDB for virtually any programming language.
Scalability
If you expect your project to continuously evolve, MongoDB is the perfect database for you, as it will allow you to grow vertically as well as horizontally.
Queries
MongoDB allows us to create powerful queries with less code, saving a lot of time and making us more efficient when analyzing the metrics of our projects.
Open source
This is probably the biggest advantage of MongoDB, since you don't have to pay for licenses to use it within your project.
How to Install MongoDB on Catalina OS
First things first: make sure you have the following: Catalina macOS and familiarity with the command terminal on your Mac. Once you do, follow the instructions below.
Download the MongoDB installation files:
MongoDB recommends that we use the more complete version of MongoDB Server, so we recommend downloading the MongoDB Enterprise version for macOS in TGZ format.
2. Extract the files:
$tar -xvzf [name-of-the-file.tgz]
3. Copy all files within the bin folder into the root:
$ cd [name-of-the-folder]/bin
$ sudo bash
$ cp * /usr/local/bin
$ exit
4. Create the folder for the database:
$ sudo bash
$ mkdir -p ~/data/db
$ chmod 777 ~/data
$ chmod 777 ~/data/db
$ exit
5. Create the configuration file for MongoDB:
$ touch /usr/local/etc/mongod.conf
6. Modify the database path:
Write the following into the file you just created:
storage: dbPath: /Users/[youruser]/data/db
7. Create an alias to overwrite the default MongoDB settings:
You will have to modify your .zshrc file by adding the following:
alias mongod='mongod -f /usr/local/etc/mongod.conf'
Done! Now you can run the mongod command on our terminal and use MongoDB normally.
Databases are a small but incredibly important part of the programming world. And if you already know how to program or are just learning and want to take your skills to the next level, then you should look into our Web Development Bootcamp, where we will teach you how to use non-relational databases and many other tools that will help you become a full stack developer.