- Install mongodb community edition
- Install and configure
mongosh
- Create a configuration file
/etc/mongod.conf
(you may need to create it with sudo
). Copy the following snippet and replace <username>
with your username and paste it:
processManagement:
fork: true
net:
bindIp: localhost
port: 27017
storage:
dbPath: /Users/<username>/data/db
systemLog:
destination: file
path: "/Users/<username>/data/log/mongodb/mongod.log"
logAppend: true
storage:
journal:
enabled: true
- Open
~/.bash_profile
and append the followin bash snippet
alias mongodstart="mongod --config /etc/mongod.conf"
mongod_stop() {
local mongopid=`less ~/data/db/mongod.lock`;
if [[ $mongopid =~ [[:digit:]] ]]; then
sudo kill -15 $mongopid;
echo mongod process $mongopid terminated;
else
echo mongod process $mongopid not exist;
fi
}
alias mongodstop="mongod_stop"
- Run
source ~/.bash_profile
- Start and stop
mongod
server using mongodstart
and mongodstop
command
- Once the deamon started successfully, run
mongosh
to connect to your local mongodb database (You can use mongo
but mongosh
is better!*)
*Read mongod, mongo, mongosh, mongos, what now?