Mongo has a very good tutorial for us to install MongoDB Community Verison at: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ (Note: the link is for Ubuntu. Just look for other systems via the page, and by the time of this writing, MongoDB does not officially support Ubuntu 22.04 yet)
By default, MongoDB has no enabled access control, so there is no default user or password. But you can only access it via Localhost. Here is my default setup after installation.
>mongosh // run from command line to login mongo shell
db.createUser( {
user: "admin", pwd: "STRONGPASS",
roles: [ { role: "root", db: "admin" } ]
} )
>mongosh // run from command line to login mongo shell
db.createUser({
user: "powerUser" , pwd: "STRONGPASS",
roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]
})
net:
port: 27017
bindIp: 127.0.0.1,BOXIP
security:
authorization: 'enabled'
Edit mongo.config (by default under /etc) by uncommenting ‘security’ and adding “authorization: 'enabled'”
. To allow remote access, bind the box IP (ex: your VPS IP).
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2022-07-06 15:04:47 EDT; 1s ago
Docs: https://docs.mongodb.org/manual
Process: 52747 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=48)
Main PID: 52747 (code=exited, status=48)
Jul 06 15:04:47 ubuntu-s-2vcpu-4gb-intel-sfo3-01 systemd[1]: Started MongoDB Database Server.
Jul 06 15:04:47 ubuntu-s-2vcpu-4gb-intel-sfo3-01 systemd[1]: mongod.service: Main process exited, code=exited, status=48/n/a
Jul 06 15:04:47 ubuntu-s-2vcpu-4gb-intel-sfo3-01 systemd[1]: mongod.service: Failed with result 'exit-code'.