Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

create new EC2 instance on Amazon Linux AMI platform

SSH into the instance

on the terminal, create the file

vi /etc/yum.repos.d/mongodb-org-4.0.repo

press i into insert mode, copy&past the following to the created file

name=MongoDB Repository

enter :wq to save content and exit insert mode

Then install MongoDB by following command

sudo yum install -y mongodb-org

Start mongoDB server

sudo service mongod start

Verify MongoDB is running

cat /var/log/mongodb/mongod.log

You should find [initandlisten] waiting for connections on port <port> somewhere in the log file.

Stop MongoDB server

sudo service mongod stop

Restart MongoDB server

sudo service mongod restart

Start a MongoDB shell

mongo --host

Stop and uninstall MongoDB

sudo service mongod stop
sudo yum erase $(rpm -qa | grep mongodb-org)
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment