As we discuss MongoDB in the previous Article About MongoDB, Why we use it? MongoDB’s Terminology and Implementation , MongoDB is an open-source NoSQL database.
Lots enhancements are released with the latest version MongoDB 4.2 to become more stable version easy to use in development and scaling.
MongoDB is a document-oriented database presented as two versions are released:
- MongoDB Community is the source available and free to use edition of MongoDB.
- MongoDB Enterprise is available as part of the MongoDB Enterprise Advanced subscription.
So in this tutorial we will show how to install MongoDB Community Edition using the package management system for these specifications as below:
- MongoDB’s version : MongoDB 4.2
- OS Server :Centos 7
- System architecture : 64-bit system
- User : non-root user with sudo privileges
First, to prepare MongoDB’s installation directly using the package management system (yum), it is required to add the MongoDB repository and configure the yum repository configuration file mongodb.repo:
- Create the configuration file mongodb.repo using the vi editor in the yum repository:
- Add this content to mongodb.repo file:
- We should verify that the MongoDB repository is created within the package management utility yum using the command repolist:
Second, now we can install mongodb-org package directly using the package management system (yum).There is no easy that this command below to launch the yum package manager and it will automatically install the latest stable version available MongoDB and all its dependencies:
# sudo yum install –y mongodb-org
In the next step, we have just to start MongoDB service using the systemctl utility that launch the MongoDB init script as show the next command:
#sudo systemctl start mongod.service
- To verify that the service started since no output is provided after start command’s execution, so we can check the end of the mongod.log file with the tail command as following:
#sudo tail /var/log/mongodb/mongod.log
- To configure MongoDB service to autostart on system boot, we use the systemctl utility:
#sudo systemctl enable mongod.service
- To check installed MongoDB version, we can use the following command :
# mongod –version
- To check the status of MongoDB database, we can use the following command:
# sudo systemctl status mongod.service
- To reload the daemon process of MongDB database : mongod process that is primarily, used to manage database access, we issue the following command ; This command requests that the daemon process reads the configuration file /etc/mongod.conf and applies any changes without any restart.
# sudo systemctl reload mongod
- To connect MongoDB using the command line, go on it is easy:
> use mydb;
- To stop MongoDB database , we issue this command that will halt all running mongod processes :
#sudo systemctl stop mongod
859 views last month, 1 views today