Setup MongoDB
Setup MongoDB
MongoDB is a database program that you will use to save and access information about users of the websites that you build. By the end of this article, you will be able to run MongoDB on your computer.
We have provided setup instructions for Mac and Windows operating systems. If your computer notifies you of any firewall or permissioning issues, you should Allow the process.
Mac OS X
- Open a new terminal session.
- Check if Homebrew is already installed on your computer — Homebrew is software that your computer uses to install other software. We will use it in the steps that follow to install MongoDB. Run the following command in your terminal to check if Homebrew is already installed:$ brew --versionIf your computer does not have Homebrew, it will respond with `command not found`. If you see this, move to step three.If Homebrew is installed, your terminal will output `Homebrew 1.3.6`. If you see this output, check the version of your operating system. If your operating system is High Sierra, you mustuninstall brew, then proceed to step 3 — High Sierra introduced apermissioning issuethat impacts old versions of homebrew.If you see `Homebrew 1.x.x` and have not updated to High Sierra, skip to step 4.
- Homebrew Installation — Paste the command from theHomebrew installation pageinto your terminal. The terminal may ask you to enter your password. This step may take a few minutes.
- MongoDB Installation — Paste the following command into your terminal to install MongoDB to your computer.brew install mongodb
- Create a Mongo data directory — This directory is where MongoDB stores database files for full-stack web applications that you run on your computer. Paste the following command into your terminal to create the Mongo data directory:mkdir -p ~/data/dbYou will not see any output in your terminal from the command above. It will create a new folder in your Home Directory.
- Start a Mongo process — Before you run a full-stack web application locally, you must start a Mongo process in the background. The following command starts an instance of MongoDB that handles data requests, manages data access, and performs background management operations while you use your web application. If you are prompted with a popup that says, "Do you want the application mongod to accept incoming network connections", click Allow.mongod --dbpath ~/data/dbIf Mongo starts correctly, you should see something like:connection accepted from ... #1 (1 connection now open)Nice Job! You just started an instance of MongoDB.
- How to kill a Mongo process — When you're done using your Mongo process, or think your current process has gotten into a bad state, navigate to the window that is running your Mongo process and follow the steps below:PressCTRL+Cto exit the Mongo process
$ brew --version
brew install mongodb
mkdir -p ~/data/db
mongod --dbpath ~/data/db
connection accepted from ... #1 (1 connection now open)
Windows
- Download — Open theMongoDB download center page, and download the latest version of MongoDB for your windows machine.
- Install — Open the installation file that you downloaded. Follow the steps to install MongoDB on your computer.
- Create a Mongo data directory — This directory is where MongoDB stores database files for full-stack web applications that you run locally. Open powershell, and enter the following command to create the Mongo data directory:md \data\db
- Start a Mongo process — Before you run a full-stack web application locally, you must start a Mongo process in the background. The following command starts an instance of MongoDB that handles data requests, manages data access, and performs background management operations while you use your web application.& 'C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe'If Mongo starts correctly, you should see something like:connection accepted from ... #1 (1 connection now open)
- How to kill a Mongo process — When you're done using your Mongo process, or think your current process is in a bad state, navigate to the window that is running Mongo and:Press "control" and the letter "C" (CTRL+C) to exit the Mongo process. PressCTRL+Cand close your terminal window.
md \data\db
& 'C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe'
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Complete Payment to Unlock Full Guide & Source Code
You are viewing the 30% preview. Join TopCourseAI Pro to unlock the remaining 70% of this article, unblur all code snippets, and gain full access to all 412 technical projects and guides.
Ready to access the complete step-by-step tutorial?
Gain full unhindered access to all 412 technical projects and guides, unblur all source code snippets, and download runnable scripts.
Related Blueprints & Guides
View all 166 →Android Studio Quick-Start Guide
Android Studio often intimidates beginners, but by learning a few handy shortcuts and getting the lay of the land, we can navigate this powerful development environment with ease.
Developer toolsApache Kafka Tutorial: A Complete Guide for Beginners
Apache Kafkais a well-known distributed event streaming platform designed to efficiently manage real-time data feeds. It was originally developed by LinkedIn in 2011 and later open-sourced. Apache Kafka has gained immens...
Developer toolsBuilding Websites with Wix
Creating a website has never been easier. Previously, making a presentable website meant learning HTML, CSS, andJavaScript. The whole process could take weeks, months, or even years before creating a website that you’re...
Ready to build production-grade AI systems?
Enjoyed this guide? Continue exploring our library of 166+ production blueprints, multi-agent swarms, and autonomous agent systems with 100% unblurred, executable source code.