Install and Configure MongoDB on AWS EC2 Linux Instance

Install and Configure MongoDB on AWS EC2 Linux Instance


In this tutorial, I will show you how to install and configure MongoDB on AWS EC2 Linux instance.

Don't Want To Read? Watch Video:


Please follow below steps one by one to install and configure properly.

Step 1: Create the below file using nano or any other editor for MongoDB

>> sudo nano /etc/yum.repos.d/mongodb-org-4.0.repo

and add the below content in the above file:

[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

Note: You can check latest MongoDB repository version from here https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/ and change it in above content and command as per requirement.

Step 2: Install MongoDB using below command

>> sudo yum install -y mongodb-org

Step 3: Start MongoDB service using below command

>> sudo service mongod start

Step 4: Start MongoDB on EC2 instance reboot
This is optional, if you want to start MongoDB after EC2 instance reboot then use command below

>> sudo chkconfig mongod on

Once the service is started, We can connect to Mongo shell using below command:

>> mongo

Check existing databases using below command

>> show dbs

Step 6: We can select database using below command

>> use admin


#Uninstall MongoDB Community Edition

Step 1: Stop mongod process by using following command:

>> sudo service mongod stop


Step 2: Remove MongoDB packages which we had installed previously

>> sudo yum erase $(rpm -qa | grep mongodb-org)

Step 3: Remove data directories like MongoDB databases and log files.

>> sudo rm -r /var/log/mongodb
>> sudo rm -r /var/lib/mongo


That's It!!! In next post we will see how to do CRUD operation using Mongo shell commands.

Happy Learning AWS Services!!!! :) Still Doubts? lets put your questions in below comment box! Thanks! 

Please like and subscribe this channel. Your 1 subscription is very important to grow channel!









Install and Configure MongoDB on AWS EC2 Linux Instance Install and Configure MongoDB on AWS EC2 Linux Instance Reviewed by Web Technology Funda on 4:53:00 AM Rating: 5

No comments

Free! Free!Free! Subscribe to Get Free PHP (Magento) tutorial Update in Your Inbox!!! Hurry Up!!!