Installing MongoDB

You can learn how to install MongoDB on its official site at https://www.mongodb.com. We strongly recommend you to use Docker for your development environment instead of installing MongoDB on your local machine. So, let's see how you can install MongoDB using Docker containers.

First, you will need to download Docker from its official site, https://www.docker.com. Once the download is completed, go ahead and install it. If you are working on MacOS or Windows, Docker will also install another tool called Kitematic. When the installation is done, look for mongo in the Containers section. Then, hit CREATE. Take a look at the following screenshot:

The tool will download the image and once it is done, it will run the MongoDB container and provide us the host and port where MongoDB is running, as illustrated:

For users who are using Linux, execute the following command to create a MongoDB container:

> docker run -p 27017:27017 -v $(pwd)/data:data/db mongo

The previous command will start a new container and exposes its internal port 27017 and will share a directory called data from your host to the container. By doing this, we can persist the container information into our host file system.

Once we have our MongoDB database running on top of Docker, we need to practice a little bit with MongoDB.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset