Installing MongoDB
You can install MongoDB Community Edition locally or run it in a Docker container.
In this page:
Installing MongoDB
On Linux use your package manager after adding the MongoDB repository, on macOS use Homebrew, and on Windows use the MSI installer. Docker is the quickest way: run the official mongo image and connect to port 27017.
Install mongosh separately if it is not included.
Note:
Docker lets you try MongoDB without installing anything on your machine.
Example: Installing MongoDB
# macOS
$ brew tap mongodb/brew && brew install mongodb-community
$ brew services start mongodb-community
# Docker (any OS)
$ docker run -d --name mongo -p 27017:27017 mongo:7
$ docker exec -it mongo mongosh
Current Mongosh Log ID: 65a1b2c3d4e5f60718293a4b
test>
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
Common Mistakes
- Forgetting to start the mongod service
- Exposing port 27017 to the internet without authentication
- Not installing mongosh
Chapter Summary
- Install Community Edition or use Docker
- mongod is the server, mongosh is the shell
- Default port is 27017
- Enable authentication before exposing it
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: