Install MongoDB in Ubuntu

To install MongoDB in Ubuntu/Debian, run

apt install mongodb

Configuration file for MongoDB is

/etc/mongodb.conf

To see status of MongoDB, run

systemctl status mongodb

To start/stop

systemctl start mongodb
systemctl stop mongodb

Create a User

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

vi /etc/mongodb.conf

Uncomment the line

auth = true

Restart MongoDB

systemctl restart mongodb

Now you can login with

mongo -u  "root" -p "serverok123" --authenticationDatabase "admin"

To verify all works, run some command, for example

show dbs

On Ubuntu 18.04, default MongoDB version is

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
> 

MongoDB

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *