How to install MongoDB database server on LinuxONE Community Cloud

Open source software (IBMZ/LinuxONE). MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time

At a high level, MongoDB enables developers that use data to build easily, adapt quickly, and scale reliably. In this tutorial, We will be using RHEL 7.8

Prerequisites

  1. Request access to LinuxONE Community Cloud. Follow instructions here

Step 1: Configure repository

1.1 Create a repo file so that you can install MongoDB enterprise directly using yum

For RHEL 7.8:

# sudo vi /etc/yum.repos.d/mongodb-enterprise-4.4.repo
#[mongodb-enterprise-4.4]
 name=MongoDB Enterprise Repository
 baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/4.4/$basearch/
 gpgcheck=1
 enabled=1
 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc

1.2 Save and quite vi

# wq:

Step 2: Install MongoDB database server on LinuxONE Community Cloud

2.1 Install MongoDB Install the MongoDB Enterprise packages For RHEL 7.8:

# sudo yum install -y mongodb-enterprise

Screenshot 2020-08-18 at 06 56 44

Screenshot 2020-08-18 at 06 57 15

Step 3: Configure MongoDB server

3.1 Start MongoDB

# sudo systemctl start mongod

If you receive an error similar to the following when starting mongod:

Failed to start mongod.service: Unit mongod.service not found.

Run the following command first:

# sudo systemctl daemon-reload

3.2 Enable MongoDB

# sudo systemctl enable mongod

3.3 Check status of the MongoDB server

# sudo systemctl status mongod

Screenshot 2020-08-18 at 07 00 54

3.4 MongoDB Shell

 # mongo

Screenshot 2020-08-18 at 07

Step 4: Create MongoDB Collections

4.1 Show existing database

# show dbs; 

Screenshot 2020-08-18 at 07 48 44

4.2 Create database

# use demo_db

Screenshot 2020-08-18 at 10 02 57

4.3 Create Collection

# db.createCollection('user'); 

The output of the above should result:

{ "ok" : 1 }

4.4 Show collections

# show collections;

The output of the above should result:

   user

4.5 Insert

# db.user.insert({"name":"Phila"});

Screenshot 2020-08-18 at 10 06 36

4.6 Find collection

# db.user.find();

The output of the above should result:

{ "_id" : ObjectId("5f3b6b0a3b6976978ce646c1"), "name" : "Phila" } 

4.7 Delete collection

# db.user.drop()

The output of the above should result:

true

4.8 Show collections

# show collections;

Well Done!