MongoDB is a NoSQL database technology. Why use it?

You can setup Ubuntu 16.04 on Amazon Web Services (AWS).

Step 1 – Add repository

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

Output after adding repository

Executing: /tmp/tmp.59u0DRiBJM/gpg.1.sh --keyserver
hkp://keyserver.ubuntu.com:80
--recv
9DA31620334BD75D9DCB49F368818C72E52529D4
gpg: requesting key E52529D4 from hkp server keyserver.ubuntu.com
gpg: key E52529D4: public key "MongoDB 4.0 Release Signing Key <packaging@mongodb.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

Step 2 – Create a list file for MongoDB

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Output

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

Step 3Reload local packages

$ sudo apt-get update

Step 4Install latest version of MongoDB

$ sudo apt-get install -y mongodb-org

Step 5Start MongoDB

$ sudo service mongod start

Step 6Verify if it is running

$ sudo tail -n 1000 /var/log/mongodb/mongod.log

Output

2019-07-04T03:49:47.409+0000 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-07-04T03:49:47.585+0000 I CONTROL  [initandlisten] MongoDB starting : pid=3201 port=27017 dbpath=/var/lib/mongodb 64-bit host=ip-10-0-1-41
2019-07-04T03:49:47.585+0000 I CONTROL  [initandlisten] db version v4.0.10
2019-07-04T03:49:47.585+0000 I CONTROL  [initandlisten] git version: c389e7f69f637f7a1ac3cc9fae843b635f20b766
2019-07-04T03:49:47.585+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2019-07-04T03:49:47.585+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2019-07-04T03:49:47.585+0000 I CONTROL  [initandlisten] modules: none
2019-07-04T03:49:47.585+0000 I CONTROL  [initandlisten] build environment:
2019-07-04T03:49:47.585+0000 I CONTROL  [initandlisten]     distmod: ubuntu1604
2019-07-04T03:49:47.585+0000 I CONTROL  [initandlisten]     distarch: x86_64
2019-07-04T03:49:47.585+0000 I CONTROL  [initandlisten]     target_arch: x86_64

Step 7MongoDB access configuration

To enable connection from another machine make changes to the config file.

$ sudo vi /etc/mongod.conf

Add private IP address of the MongoDB server. For example, if the IP address is 10.0.1.41 make the following change.

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,10.0.1.41

Restart MongoDB server.

$ sudo service mongod restart

Check MongoDB status.

$ mongo status

Output

MongoDB shell version v4.0.10
connecting to: mongodb://127.0.0.1:27017/status?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("fad05546-9340-429e-a7b2-b13b091a1cbe") }
MongoDB server version: 4.0.10
Server has startup warnings: 
2019-07-05T01:23:22.247+0000 I STORAGE  [initandlisten] 
2019-07-05T01:23:22.247+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-07-05T01:23:22.247+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-07-05T01:23:23.312+0000 I CONTROL  [initandlisten] 
2019-07-05T01:23:23.312+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-07-05T01:23:23.312+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-07-05T01:23:23.312+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()
---
>

Type exit

Step 8Install MongoDB Compass

Download MongoDB Compass to connect to the Database.

The following screenshot shows how to connect to a MongoDB server on a private network behind a Bastion server.