How to Install MongoDB on ubuntu 16.04

To Install MongoDB  on Ubuntu 16.04

MongoDB is an open-source, cross-platform, document-oriented database which stores data in JSON-like documents. The main features of MongoDB are Ahoc queries, indexing, load balancing and file storage. It is the fourth popular database system.   It is so simple to install MongoDB database on Ubuntu 16.04, and this article sheds light on the same process. 

 

Installing MongoDB

First, it is essential to get the MongoDB packages, and since they are available on Ubuntu repositories, you don’ t have to worry about it. However, the packaged version is not latest and stable you can check it out by executing the following command.

root@linuxhelp:~# sudo apt-cache policy mongodb
 Installed: (none)
 Candidate: 1:2.6.10-0ubuntu1
  Version table:
  1:2.6.10-0ubuntu1 500
   500 http://in.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages

 

We need to retrieve a newer version, so you can use the official MongoDB repository for that purpose. You can do that by importing the MongoDB Public Key as follows.

root@linuxhelp:~# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Executing: /tmp/tmp.n7U1bG0RN8/gpg.1.sh &ndash keyserver
.
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)


And then, you need to create a List File for MongoDB by making use of the following command. 

root@linuxhelp:~# echo " deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse"  | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

 

And add this in it.

deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse

 

After that, you need to reload the apt packages database by executing the following command.

root@linuxhelp:~# sudo apt-get update
Ign:1 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 InRelease                 
Hit:2 http://security.ubuntu.com/ubuntu xenial-security InRelease     
.
Fetched 40.0 kB in 2s (17.0 kB/s)    
Reading package lists... Done

 

Once the update is done, you shall proceed with the installation of MongoDB

root@linuxhelp:~# sudo apt-get install mongodb-org -y
Reading package lists... Done
.
Done.
Adding user `mongodb'  to group `mongodb'  ...
Adding user mongodb to group mongodb

As the installation gets complete, you’ ll notice that a new unit file for system is created, and islocated in /lib/systemd/system, so you can launch MongoDB with the systemctl tool.


 

As previously mentioned, you can use systemctl to start MongoDB and for that, you need to run the following command.

root@linuxhelp:~# sudo systemctl start mongod

 

After that, check the MongoDB status by running the following command.

root@linuxhelp:~# systemctl status mongod

mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/lib/systemd/system/mongod.service  disabled  vendor preset: 
   Active: active (running) since ...

 

Next, enable automatic starting at boot time as follows.

root@linuxhelp:~# systemctl enable mongod

With this, MongoDB installation is complete.

 

When MongoDB service is running, just execute the following command for starting MongoDB shell

root@linuxhelp:~# mongo

 

 

In the shell, execute the help command for a list of available commands:

>  help


The following output will be displayed. 

db.help()                    help on db methods
db.mycoll.help()             help on collection methods
.
.
.
exit                         quit the mongo shell

With this, this tutorial on installing MongoDB Community Edition on an Ubuntu 16.04 comes to an end. 


 

FAQ
Q
What does the leaf mean in the MongoDB logo?
A
Our founders believe that coding should be natural, and so should using a database. They want the experience of using MongoDB to be simple and natural. Thus, the leaf.
Q
Does MongoDB support ACID transactions?
A
Yes. MongoDB 4.0 added support for multi-document ACID transactions.
Q
Why is MongoDB useful?
A
MongoDB provides a technology foundation that enables development teams through:

The document data model – presenting them the best way to work with data.

A distributed systems design – allowing them to intelligently put data where they want it.
Q
What is Mongodb Atlas?
A
MongoDB Atlas is a cloud-hosted MongoDB service engineered and run by the same team that builds the database It incorporates operational best practices we've learned from optimizing thousan
Q
What is a MongoDB shard?
A
Sharding is the process of storing data records across multiple machines and it is MongoDB's approach to meeting the demands of data growth. As the size of the data increases, a single mach