List out basic commands to use MongoDB Community Edition 7.0 with MacOS
- Tap the MongoDB Homebrew Tap to download the official Homebrew formula for MongoDB and the Database Tools:
brew tap mongodb/brew
- To update Homebrew and all existing formulae:
brew update
- To install MongoDB:
brew install mongodb-community@7.0
The installation includes the following binaries:
Intel Processor | Apple Silicon Processor | |
---|---|---|
configuration file | /usr/local/etc/mongod.conf | /opt/homebrew/etc/mongod.conf |
log directory | /usr/local/var/log/mongodb | /opt/homebrew/var/log/mongodb |
data directory | /usr/local/var/mongodb | /opt/homebrew/var/mongodb |
-
To run MongoDB (i.e. the mongod process) as a macOS service, run:
brew services start mongodb-community@7.0
-
To stop a mongod running as a macOS service:
brew services stop mongodb-community@7.0
-
To verify that MongoDB is running
brew services list
-
To run mongod manually using a config file, run:
For macOS running Intel processors:
mongod --config /usr/local/etc/mongod.conf --fork
For macOS running on Apple Silicon processors:
mongod --config /opt/homebrew/etc/mongod.conf --fork
-
To run mongod manually specifying --dbpath and --logpath on the command line, run:
mongod --dbpath /path/to/dbdir --logpath /path/to/mongodb.log --fork
-
To stop a mongod running, connect to the mongod using mongosh, and issue the
shutdown
command as needed. -
To verify that MongoDB is running:
ps aux | grep -v grep | grep mongod
Log file of mongod process:
/usr/local/var/log/mongodb/mongo.log
.
To begin using MongoDB, connect mongosh to the running instance. From a new terminal, issue the following:
- monitoring tools:
mongosh
-
To view:
cat /opt/homebrew/etc/mongod.conf
Output:
systemLog: destination: file path: /opt/homebrew/var/log/mongodb/mongo.log logAppend: true storage: dbPath: /opt/homebrew/var/mongodb net: bindIp: 127.0.0.1, ::1 ipv6: true