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 on Ubuntu 18.04 LTS Bionic Beaver.
Before starting installation, lets first update package index.
apt update -y
MongoDB package is already present in official 18.04 repository. But it is a very old version. To get the latest stable version, we will install it using official MongoDB repository. (4.0 is the latest stable version when writing this article).
Lets first import public key of this repository.
wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add -
Now create list file /etc/apt/sources.list.d/mongodb-org-4.0.list and add below content.
deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse
MongoDB service will be started automatically after installation. You can see status of service using below command.
systemctl status mongodb.service
In case it is not started, start it manually using command –
systemctl start mongodb.service
To start mongodb service automatically on boot, use following command.
systemctl enable mongodb.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 Ubuntu 18.04 Bionic Beaver using official MongoDB repo. If you have any doubt or suggestions, feel free to put them in comments.