MongoDB is Document-oriented database system. It is part of the NoSQL family of database systems. Instead of storing data in tables as is done in a "classical" relational database, MongoDB stores structured data as JSON-like documents.
Prerequisites
1. Java
2. Linux 64 Bit OS (Ubuntu/Debian)
Installing MongoDB
Import
the public key used by the package management system.
$sudo
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 –recv 0C49F3730359A14518585931BC711F9BA15703C6
|
Create the
/etc/apt/sources.list.d/mongodb-org-3.4.list list file using the command
appropriate for your version of Ubuntu.
Ubuntu 12.04:
$sudo
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4
multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
Ubuntu 14.04:
$sudo
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu
trusty/mongodb-org/3.4 multiverse" | sudo tee
/etc/apt/sources.list.d/mongodb-org-3.4.list
Ubuntu 16.04:
$sudo
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.
|
Reload local package database
$sudo
apt-get update
|
Reload Install the MongoDB packages. (Install the
latest stable version of MongoDB).
$sudo
apt-get install -y mongodb-org
|
Start MongoDB
$sudo
service mongod start
|
Verify that MongoDB has started successfully
$sudo
service mongod status
|
Check below file successfully created or not.
$cd /var/log/mongodb/
$ls –l
mongod.log
$cd
/etc
$ls -l
mongod.conf
|
Stop Mongodb service and modify mongod.conf file in
case of need to add Ip address. (Default bindIp: 127.0.0.1)
$sudo
service mongod stop
$sudo
nano /etc/mongod.conf
|
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
port: 27017
bindIp: 127.0.0.1,localhost
|
Change the read & write permission of data
directory
$sudo
chmod 776 /var/lib/mongodb/*
|
Check Mongodb start with both IP addresses.
$sudo
service mongod start
$netstat
-nlp | grep 27017
tcp 0
0 localhost:27017
0.0.0.0:* LISTEN -
tcp 0
0 127.0.0.1:27017
0.0.0.0:* LISTEN -
|
Enter into Mongodb shell with IP address.
$sudo
mongo localhost:27017
MongoDB
shell version v3.4.3
connecting
to: localhost:27017
MongoDB
server version: 3.4.3
>
|