MongoDB Installation
1. Install MongoDB on Mac (Homebrew Method)
Since you are using Homebrew, the easiest way to install MongoDB is through it.
A. Update Homebrew
First, update Homebrew to ensure you get the latest MongoDB version:
B. Install MongoDB Community Edition
Run the following command to install MongoDB:
🔹 7.0
is the latest version at the time of writing. You can check for newer versions here.
C. Start the MongoDB Service
After installation, start MongoDB using:
✅ This will run MongoDB in the background as a service.
To check if MongoDB is running, use:
2. Verify the Installation
A. Check MongoDB Version
Confirm MongoDB is installed by running:
You should see an output like this:
B. Connect to MongoDB Shell
To interact with MongoDB, open the shell:
If connected successfully, you will see:
Now, you can start using MongoDB commands.
3. Set Up the MongoDB Data Directory (If Needed)
By default, MongoDB stores data in /usr/local/var/mongodb
. If MongoDB fails to start, manually create the directory:
Then, restart MongoDB:
4. Create a Test Database
Inside mongosh
, run:
✅ This confirms MongoDB is working correctly.
5. Stop and Restart MongoDB
A. Stop MongoDB
B. Restart MongoDB
6. Uninstall MongoDB (If Needed)
To remove MongoDB from your Mac:
7. Next Steps
🔹 Install Mongoose (npm install mongoose
) to use MongoDB with Node.js.
🔹 Set Up MongoDB Compass (GUI for MongoDB) from here.
🔹 Secure MongoDB with Authentication if deploying to production.
Would you like help setting up a MongoDB project? 🚀