Install MongoDB in Ubuntu
To install MongoDB in Ubuntu/Debian, run
1 |
apt install mongodb |
Configuration file for MongoDB is
1 |
/etc/mongodb.conf |
To see status of MongoDB, run
1 |
systemctl status mongodb |
To start/stop
1 2 |
systemctl start mongodb systemctl stop mongodb |
Create a User
1 2 3 |
mongo use admin db.createUser({user: "root", pwd: "serverok123", roles:["root"]}) |
Now you need to enable authentication, this can be done by editing /etc/mongodb.conf
1 |
vi /etc/mongodb.conf |
Uncomment the line
1 |
auth = true |
Restart MongoDB
1 |
systemctl restart mongodb |
Now you can login with
1 |
mongo -u "root" -p "serverok123" --authenticationDatabase "admin" |
To verify all works, run some command, for example
1 |
show dbs |
On Ubuntu 18.04, default MongoDB version is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
ubuntu@ip-172-31-8-76:~$ mongo -u "root" -p "serverok123" --authenticationDatabase "admin" MongoDB shell version v3.6.3 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.6.3 Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user Server has startup warnings: 2018-12-22T17:06:15.171+0000 I STORAGE [initandlisten] 2018-12-22T17:06:15.171+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 2018-12-22T17:06:15.171+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem > db.version() 3.6.3 > |