MongoDB is one of the most popular NoSQL database. It is an ideal choice to store morphing data or schema-less data where schema can’t be specified. To store such data, MongoDB uses documents and collections instead of tables and columns from relational database. Along with Free Community Edition, MongoDB also comes with Advanced Enterprise Subscription and on-demand fully managed service. In this article, we will see how to install Free Community Edition of MongoDB.
Before starting installation, lets first update package index.
yum update -y
MongoDB package is not present in CentOS-7-package-repository. Our first choice was EPEL repo. But version in EPEL is too old and strangely it didn’t work. So we will install MongoDB from official repository. Lets enable this repository first. Create new file /etc/yum.repos.d/mongodb-org.repo using your favorite editor and add below content.
[mongodb-org-4.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
Update package index again.
yum update -y
Now install MongoDB meta-package. As of writing this article, stable version of MongoDB is 4.0.
yum install -y mongodb-org
Start MongoDB service using below command.
systemctl start mongod.service
Make sure service is running by checking status of service
systemctl status mongod.service
To start mongod service automatically on boot, use below command
systemctl enable mongod.service
Connect to Database
When you install MongoDB server, MongoDB tools are also installed. Use below command to connect MongoDB.
If all is good, you can see Mongo Shell prompt.
You can easily find badly configured MongoDB instances all over internet. Considering seriousness of this topic, we decided to write separate article on securing your MongoDB installation. You can visit it here.
In this article, we installed MongoDB-4.0 on CentOS-7 using official MongoDB repo. If you have any doubt or suggestions, feel free to put them in comments.