DEV Community

loading...
Cover image for Ultimate guide to install and launch MongoDB on macOs

Ultimate guide to install and launch MongoDB on macOs

honorezemagho
Fullstack Web Developer PHP-Laravel, Web Enthusiast, Opensource Contributor. I love to learn and explore new things related to new technologies πŸ’ͺ πŸ’ͺ
・Updated on ・2 min read

Today we are going to learn how to install and launch MongoDB on macOS.
We are going to start with the prerequisites, MongoDB Installation, How to launch MongoDB and the Default configuration files.

Introduction

MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.

In this tutorial, we are going to set up step by step MongoDB on macOS.

1. Prerequisites

Homebrew
Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple's macOS operating system and Linux.

First of all, you need to verify is homebrew is already installed with the command :

brew -v
// Output if it’s installed
// Homebrew 2.4.15
// Homebrew/homebrew-core (git revision 872ea; last commit 2020-08-31)
Enter fullscreen mode Exit fullscreen mode

To install it, we need to use the command below :

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

It can take a while to install just be patient.
For further documentation, you can check out this link.

2. MongoDB Installation

First, we need to up brew dependencies with the command :

brew update
Enter fullscreen mode Exit fullscreen mode

After we need to find the MongoDB Tap:

brew tap mongodb/brew
Enter fullscreen mode Exit fullscreen mode

brew tap adds more repositories to the list of formulae that brew tracks, updates, and installs from. By default, tap assumes that the repositories come from GitHub.

We can install now MongoDB community Edition on our Computer using this command:

brew install mongodb-community
Enter fullscreen mode Exit fullscreen mode

3. Launch MongoDB

To have launchd start mongod immediately and also restart at login, use:

brew services start mongodb-community
Enter fullscreen mode Exit fullscreen mode

To connect to mongodb use the command :

mongo
Enter fullscreen mode Exit fullscreen mode

If there is an error

if for any reason you have an error, open a new terminal window and run the command:

mongod
Enter fullscreen mode Exit fullscreen mode

wait for 15 seconds and then rerun the command

mongo
Enter fullscreen mode Exit fullscreen mode

in another terminal.

4. Default Configuration Files

The configuration file (/usr/local/etc/mongod.conf)
The log directory path (/usr/local/var/log/mongodb)
The data directory path (/usr/local/var/mongodb)
Enter fullscreen mode Exit fullscreen mode

Congratulations.
We have successfully install and launch mongodb.
party-image

Discussion (0)