Back to all articles

November 20, 2020

What is MongoDB? A practical guide to MongoDB and How to Install It on Catalina OS

Ironhack - Changing The Future of Tech Education

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 recent 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 (/). That's why in this post we will teach you how to install MongoDB on Catalina macOS so that you can continue working efficiently with your Apple.

Relational vs Non-relational databases

Databases are the cornerstone of all technology platforms. Relational databases (SQL) are the ones we have always known and non-relational databases (NoSQL) are a relatively new development that took the world of technology by surprise and are here to stay. Some of the advantages of non-relational databases over relational ones are:

  • There's no redundancy.

  • They're much lighter.

  • They're 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, however it is 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:

 Bases de datos

 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.

What do we use MongoDB for?

MongoDB can be used for any application or platform that needs to store semi-structured data. MongoDB is very useful when we are looking for scalability in our projects as it allows us to grow horizontally without problems.

Why use MongoDB?

Here are a couple of reasons why you should be using MongoDB in your projects.

  • 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.

  • It's 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

Prerequisites:

  • Catalina macOS

  • Familiarity with the command terminal on your Mac

  1. 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.

.

  1. Extract the files:

$tar -xvzf [name-of-the-file.tgz]

  1. Copy all files within the bin folder into the root:

$ cd [name-of-the-folder]/bin
$ sudo bash
$ cp * /usr/local/bin
$ exit

  1. Create the folder for the database:

$ sudo bash
$ mkdir -p ~/data/db
$ chmod 777 ~/data
$ chmod 777 ~/data/db
$ exit

  1. Create the configuration file for MongoDB:

$ touch /usr/local/etc/mongod.conf

  1. Modify the database path:

Write the following into the file you just created:

storage: dbPath: /Users/[youruser]/data/db

  1. 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. 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 make you into a full stack developer.

Happy Coding! ❤️

Related Articles

Recommended for you

Ready to join?

More than 10,000 career changers and entrepreneurs launched their careers in the tech industry with Ironhack's bootcamps. Start your new career journey, and join the tech revolution!