Liwaiwai Liwaiwai
  • /
  • Artificial Intelligence
  • Machine Learning
  • Robotics
  • Engineering
    • Architecture
    • Design
    • Software
    • Hybrid Cloud
    • Data
  • Learning
  • About
  • /
  • Artificial Intelligence
  • Machine Learning
  • Robotics
  • Engineering
    • Architecture
    • Design
    • Software
    • Hybrid Cloud
    • Data
  • Learning
  • About
Liwaiwai Liwaiwai
  • /
  • Artificial Intelligence
  • Machine Learning
  • Robotics
  • Engineering
    • Architecture
    • Design
    • Software
    • Hybrid Cloud
    • Data
  • Learning
  • About
  • Programming

How To: MongoDB Installation & Configuration In Ubuntu

  • May 6, 2019
  • admin

Overview

  • MongoDB is a document-oriented database
  • Shines with document-based design. Supporting sub-documents as values instead of the usual data types, it can be perfect for retrieving a record and a sub-detail or list of records in one query.

 

Prerequisites

  • Operating System: Ubuntu 18
    • For production environments use from the following : Amazon Linux, Debian 8, RHEL / CentOS 6.2 +, SLES, Ubuntu LTS 16.04 and Windows Server 2012 R2
  • Command Line Interface or Terminal

 


Partner with liwaiwai.com
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

Installation

01. Open a terminal window

 

02. Check if MongoDB is already installed. Execute the following to determine.

$ mongo

# and

$ mongod

 

It should show some suggestion on how to install MongoDB.

 

03. At the CLI, import the public key used by the package management system. This will install an official version of MongoDB.

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

 

04. Create a list file for MongoDB

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

 

05. Reload local package database.

$ sudo apt update

 

06. Install the MongoDB packages.

$ sudo apt install mongodb-org -y

 

07. Check the version. If the version is returned, this means that MongoDB has been installed correctly.

$ mongod --version

# or

$ mongo --version

 

08. Configure MongoDB to start on system boot.

$ sudo systemctl enable mongod.service

 

09. Connect to the Mongo shell.

$ mongo

 

If you are unable to connect to the mongo shell. Try restarting the mongod service.

$ sudo service mongod restart

 

Changing the MongoDB Port

Changing the default port of MongoDB provides a first line of defense against unwanted intruders. While it isn’t a sure-way for deferring against bots that sweep through ports that tries to access database, it prevents them trying to access the database using the default port. For security it is better to enable other mechanisms such as creating database users that have specific roles and access to database with credentials.

Read More  To The Brain, Reading Computer Code Is Not The Same As Reading Language

01. Edit the MongoDB configuration file

$ sudo nano /etc/mongod.conf

 

02. While on the nano interface, press Ctrl+W (or command for Mac)  to search for the text, network interfaces. Then press Enter.

In this example change the port to 29999. After changing the port, Press Ctrl+O (or command for Mac), then Enter. Ctrl+X to exit the nano editor.

 

03. Restart MongoDB service to apply the changes

$ sudo service mongod restart

 

04. After restart, you cannot connect to the MongoDB using the default mongod command. Instead you have to identify the port.

$ mongo --port 29999

 

Adding Security and Authentication

While for development purpose the current setup will suffice. But for production it is recommended to enable authentication and add user with password for security.

01. Edit the MongoDB configuration file

$ sudo nano /etc/mongod.conf

 

02. While on the nano interface, press Ctrl+W (or command for Mac)  to search for the text, “security”. Then press Enter.

 

03. Add the following lines after the #security comment.

# security:
security:
  authorization: enabled

 

04. Restart the MongoDB service.

$ sudo service mongod restart

 

05. Access the MongoDB shell

$ mongo

# or if port has been changed

$ mongo --port

 

06. Switch to the admin database

> use admin

 

07. Create a Root user account. On the MongoDB shell, execute the following. Replace the dotlah and dotlah-password with your preferred credentials.

Note that roles here should be configured as needed. In this example, we are using the root role. For the list of roles see the following link : https://docs.mongodb.com/manual/reference/built-in-roles/

db.createUser(
  {
    user: "dotlah",
    pwd: "dotlah-password",
    roles: [ 
      { role: "root", db: "admin" } 
    ]
  }
)

It should show something similar. This shows that the user has been added.

Read More  TF Dev Summit '19 | What's New In TensorBoard

 

08. Restart the MongoDB instance with access control

> db.adminCommand({shutdown:1})

 

09. Exit from the MongoDB shell.

> exit

 

10. Test the new user by using the following authentication command.

$ mongo --port 27017 --username dotlah --password dotlah-password --authenticationDatabase admin

 

Appendix

01. Start MongoDB service

$ sudo service mongod start

 

02. Restart MongoDB service

$ sudo service mongod restart

 

03. Stop MongoDB service

$ sudo service mongod stop

 

References

For production deployment see the following resource

— https://docs.mongodb.com/manual/administration/production-notes


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

admin

Related Topics
  • Database
  • How To
  • Installation
  • MongoDB
  • NoSQL
  • Ubuntu
You May Also Like
View Post
  • Artificial Intelligence
  • Programming

How To Build An AI-generated Procedural Application

  • May 22, 2023
View Post
  • Data
  • Programming
  • Software

The Top 10 Data Interchange Or Data Exchange Format Used Today

  • May 17, 2023
View Post
  • Artificial Intelligence
  • Machine Learning
  • Programming

Running ML Models Now Easier With New Dataflow ML Innovations On Apache Beam

  • May 4, 2023
View Post
  • Programming
  • Technology

From The Field: A Programming Requirement for Structural Analysis Computations. To Java or To Javascript.

  • May 3, 2023
View Post
  • Artificial Intelligence
  • Automation
  • Programming
  • Programming Languages

Speak The Language Of The Future! Here Are The Top 10 Programming Languages For AI

  • May 2, 2023
View Post
  • Artificial Intelligence
  • Programming

PromptOps In application Delivery: Empowering Your Workflow with ChatGPT

  • April 30, 2023
View Post
  • Artificial Intelligence
  • Programming
  • Software

Bard Now Helps You Code

  • April 24, 2023
View Post
  • Machine Learning
  • Programming
  • Software Engineering

10 Best Python Machine Learning Tutorials

  • February 14, 2023
A Field Guide To A.I.
Navigate the complexities of Artificial Intelligence and unlock new perspectives in this must-have guide.
Now available in print and ebook.

charity-water



Stay Connected!
LATEST
  • OpenAI 1
    How We Interact With Information: The New Era Of Search
    • September 28, 2023
  • 2
    Bring AI To Looker With The Machine Learning Accelerator
    • September 28, 2023
  • 3
    3 Questions: A New PhD Program From The Center For Computational Science And Engineering
    • September 28, 2023
  • 4
    Microsoft And Mercy Collaborate To Empower Clinicians To Transform Patient Care With Generative AI
    • September 27, 2023
  • 5
    NASA’s Mars Rovers Could Inspire A More Ethical Future For AI
    • September 26, 2023
  • 6
    Oracle CloudWorld 2023: 6 Key Takeaways From The Big Annual Event
    • September 25, 2023
  • 7
    3 Ways AI Can Help Communities Adapt To Climate Change In Africa
    • September 25, 2023
  • Robotic Hand | Lights 8
    Nvidia H100 Tensor Core GPUs Come To Oracle Cloud
    • September 24, 2023
  • 9
    AI-Driven Tool Makes It Easy To Personalize 3D-Printable Models
    • September 22, 2023
  • 10
    Huawei: Advancing a Flourishing AI Ecosystem Together
    • September 22, 2023

about
About
Hello World!

We are liwaiwai.com. Created by programmers for programmers.

Our site aims to provide materials, guides, programming how-tos, and resources relating to artificial intelligence, machine learning and the likes.

We would like to hear from you.

If you have any questions, enquiries or would like to sponsor content, kindly reach out to us at:

[email protected]

Live long & prosper!
Most Popular
  • Coffee | Laptop | Notebook | Work 1
    First HP Work Relationship Index Shows Majority of People Worldwide Have an Unhealthy Relationship with Work
    • September 20, 2023
  • 2
    Huawei Connect 2023: Accelerating Intelligence For Shared Success
    • September 20, 2023
  • 3
    Applying Generative AI To Product Design With BigQuery DataFrames
    • September 21, 2023
  • 4
    Combining AI With A Trusted Data Approach On IBM Power To Fuel Business Outcomes
    • September 21, 2023
  • Microsoft and Adobe 5
    Microsoft And Adobe Partner To Deliver Cost Savings And Business Benefits
    • September 21, 2023
  • /
  • Artificial Intelligence
  • Explore
  • About
  • Contact Us

Input your search keywords and press Enter.