MongoDb Setup

Installing MongoDB Community Edition on Ubuntu 18.04 EC2 instance in AWS

Installing the MongoDB in ubuntu via aptitude is very simple

To install MongoDB Community on your Ubuntu system, these instructions will use the official mongodb-org package, which is maintained and supported by MongoDB Inc.

We have 2 ways to install and step mongodb on aws

  1. Directly from source

  2. Using by docker

1. Directly from source

Import the public key used by the package management system

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

Add Sources

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

Reload local package database.

sudo apt update

Install the MongoDB packages.

Start and verify the service

Enable the service start on every reboot

To access MongoDB, run the following command

By default, there are three databases that are created upon installation. These are admin, config, and local.

Create a user credential for manage remotely

You can check users list

Now create new database

create default collections

after collection created successfully now insert data for widgets and widgetsCategory collection

After all steps completed. Now exits for mongo command line and restart the mongo server using by


 

2. Using by docker

Run MongoDB with Docker Composer

Run MongoDB with Docker Composer

  • Create Docker mongo-compose.yml file and paste below code

  • and after that locate the saved directory and open AWS CLI command line

  • execute the docker compose command

  • after successfully execution code. Find the expressed url like and visit http://swarm-ip:8081, http://localhost:8081, or http://host-ip:8081 (as appropriate).

  • Create Master Database and download the json files.

  • Execute the import commands

  • Completed the steps