Skip to main content

Configuring MongoDB

Check if mongodb is running​

mongod --version

Making user for mongodb​

sudo nano /etc/mongod.conf
# network interfaces
port: 27017
bindIp: # Enter,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
To bind to all IPv4 and IPv6 address you’ll set:

To save the file press CTRL + X then press Y and then press ENTER

Restart mongodb

sudo systemctl restart mongod

Login to mongodb shell


Once your in mongodb shell type this command

> use admin
db.createUser({user:"ararat", pwd:"passwordhere", roles:[{role:"root", db:"admin"}]})

Make sure to change the password to something more secure


Next we need to edit the service file for mongodb

sudo nano /lib/systemd/system/mongod.service

Add this line into this file

ExecStart=/usr/bin/mongod --quiet --auth --config /etc/mongod.conf
sudo systemctl daemon-reload && sudo systemctl restart mongod

Check if you can login to mongodb shell with the user you created

mongosh -u ararat -p --authenticationDatabase admin
db.runCommand({connectionStatus : 1})

Now you got fully working mongodb server with user and password