MongoDB is an open source cross-platform, document-oriented database. It was designed with both scalability and developer agility in mind. MongoDB is written in C, C++, and JavaScript, and it uses JSON-like documents with dynamic schemas to store data.

 

MongoDB is released under the Server Side Public License (SSPL), and the language drivers are available under an Apache License.

 

MongoDB is available for Linux, Windows, OS X, FreeBSD, and Solaris.

 

Install MongoDB on Debian 9 / Debian 8

 

You can install MongoDB from Debian repository or Official MongoDB repository.

 

  1. Install MongoDB (v4.x) from Official MongoDB repository
  2. Install MongoDB (v3.x) from Debian Repository

 

1. Install MongoDB from MongoDB Repository

 

MongoDB Inc releases stable packages for Debian 9 and Debian 8, and their packages are generally fresher than those in the Debian repositories. You should always use the official mongodb-org package.

 

The mongodb-org package might conflict with the mongodb packages in Debian repository (If you have it already installed).

 

Install the certificate server for downloading and managing certificates.

sudo apt-get update
sudo apt install dirmngr

 

Import the public key to the system.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

 

Add the MongoDB repository to the system.

### Debian 9 ###

echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

### Debian 8 ###

echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/4.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

 

Update the repository index.

sudo apt-get update

 

Install the MongoDB packages using the apt command. The name of the MongoDB package is mongodb-org.

sudo apt-get install -y mongodb-org

 

MongoDB services can be started/stopped by the easy known commands.

 

To start MongoDB service, run.

sudo systemctl start mongod

 

To enable MongoDB service to start automatically on system startup, run:

sudo systemctl enable mongod

 

To check the status of MongoDB service, run. 

sudo systemctl status mongod

 

Output:

mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-01-28 13:27:52 UTC; 8s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 2599 (mongod)
   CGroup: /system.slice/mongod.service
           └─2599 /usr/bin/mongod --config /etc/mongod.conf

Jan 28 13:27:52 mongod9 systemd[1]: Started MongoDB Database Server.

 

Confirm the version of MongoDB.

mongod --version

 

Output:

db version v4.0.5
git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
OpenSSL version: OpenSSL 1.1.0j  20 Nov 2018
allocator: tcmalloc
modules: none
build environment:
    distmod: debian92
    distarch: x86_64
    target_arch: x86_64s

 

2. Install MongoDB from Ubuntu Repository

 

Installing MongoDB from Debian repository is a straightforward way. But, the version available in Debian repository may be bit older than the one in MongoDB repository.

 

 Note:

MongoDB Inc does not maintain the MongoDB package available in the Debian repository.

sudo apt update
sudo apt -y install mongodb mongodb-server mongo-tools

 

By this time, MongoDB should be up and running. To check the status of MongoDB, run.

sudo systemctl status mongodb

 

Output:

mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-01-28 13:37:02 UTC; 27s ago
     Docs: man:mongod(1)
 Main PID: 1608 (mongod)
   CGroup: /system.slice/mongodb.service
           └─1608 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf

Jan 28 13:37:02 mongod9c systemd[1]: Started An object/document-oriented database.

 

Confirm the version of MongoDB.

mongod --version

 

Output:

db version v3.2.11
git version: 009580ad490190ba33d1c6253ebd8d91808923e4
OpenSSL version: OpenSSL 1.0.2q  20 Nov 2018
allocator: tcmalloc
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

 

MongoDB can be started/stopped by the easy known commands.

 

To start MongoDB server, run.

sudo systemctl start mongodb

 

To stop MongoDB server, run:

sudo systemctl stop mongodb

 

Access MongoDB

 

Connect to MongoDB shell by using the mongo command.

mongo

 

Output:

MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("5a1b810c-5e24-4083-b85b-77479a3611a2") }
MongoDB server version: 4.0.5
Server has startup warnings: 
2019-01-28T13:27:53.517+0000 I STORAGE  [initandlisten] 
2019-01-28T13:27:53.517+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-01-28T13:27:53.517+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-01-28T13:27:54.229+0000 I CONTROL  [initandlisten] 
2019-01-28T13:27:54.229+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-28T13:27:54.229+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-01-28T13:27:54.229+0000 I CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

>

 

Fix MongoDB 4.x Warnings

Error 1

2019-01-28T13:27:53.517+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 
2019-01-28T13:27:53.517+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem

 

To clear this warning, we recommend you to use XFS filesystem for MongoDB.

 

Error 2

2019-01-28T13:27:54.229+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 
2019-01-28T13:27:54.229+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.

 

To clear this warning, follow the MongoDB security checklist.

 

That’s All.

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)