MongoDB is an open source NoSQL database that uses a document-oriented data model. MongoDB is built on architecture of collection and document, whereas MySQL uses tables and rows. MongoDB uses JSON-like documents with schemas.
Key features of MongoDB:
How to install MongoDB?
If we want install MongoDB directly using yum then we have to add MongoDB repository. It is recommended to follow the installation steps as a root user.
Create a /etc/yum.repos.d/mongodb-org-3.4.repo
vim /etc/yum.repos.d/mongodb-org-3.4.repo
Add the following lines in the repository file [mongodb-org-3.4]
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
Use the following command to install MongoDB
yum install -y mongodb-org
Start MongoDB
We can start mongoDB service by using following command:
servicemongod start
Verify if MongoDB has started
You can verify if MongoDB process has started or not by checking the content of MongoDB log file which is located at /var/log/mongodb/mongod.log
You should see following line in log file:
[initandlisten] waiting for connections on port 27017
Where 27017 is default port. You can configure another port in configuration file located at /etc/mongod.conf
If you want to start the MongoDB after every system reboot, you can use following command to do the same
chkconfigmongod on
Stop MongoDB
You can use following command to stop MongoDB
servicemongod stop
Restart MongoDB
You can use following command to restart MongoDB
servicemongod restart
By Default MongoDB stores its data file in /var/lib/mongo and its log file in
/var/log/mongoDB.
We can specify alternate path for data and log directory by modifying /etc/mongod.conf
Uninstall MongoDB
To remove MongoDB completely from the system, we have remove MongoDB application, related configuration files, logs files and any other directories containing data files.
Follow the below steps to remove the MongoDB
Stop MongoDB by using following command
servicemongod stop
Remove any MongoDB packages that we had previously installed
sudo yum erase $(rpm -qa | grepmongodb-org)
Remove all data and log files
sudorm -r /var/log/mongodb
sudorm -r /var/lib/mongo