Preamble
MongoDB is a free open source database of documents. It belongs to a family of databases called NoSQL, which is different from traditional table-based SQL databases such as MySQL and PostgreSQL.
In MongoDB, data is stored in flexible documents such as JSON, where fields may differ from document to document. This does not require a predefined pattern, and the data structure may change over time.
This article describes how to install and configure MongoDB Community Edition in Ubuntu 20.04.
Standard Ubuntu repositories include the outdated version of MongoDB. Installing the latest version of MongoDB in Ubuntu is quite easy. We will enable the MongoDB repository, import the GPG repository key, and install the MongoDB server.
Install MongoDB in Ubuntu 20.04
To install MongoDB in Ubuntu do the following as root or sudo user:
- Set the dependencies needed to add a new repository via HTTPS:
sudo apt update
sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common - Import the GPG repository key and add the MongoDB repository using it:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse'
At the time of writing this article, the latest version of MongoDB was version 4.4. To install another version, replace it with your preferred version. - After turning on the repository, install the meta-package mongodb-org by typing:
sudo apt install mongodb-org
The following packages will be installed in your system:
- mongodb-org-server – mongod daemon and corresponding initialization and configuration scripts.
- mongodb-org-mongos – The mongos daemon.
- mongodb-org-shell – Mongo shell, JavaScript interactive interface for MongoDB. It is used to perform administrative tasks from the command line.
- mongodb-org-tools – Contains several MongoDB tools to import and export data, statistics, and other utilities.
Start the MongoDB daemon and start it at boot by typing:
sudo systemctl enable --now mongod
To check if the installation has completed successfully, connect to the MongoDB database server with the mongo tool, and print the connection status:
mongo --eval 'db.runCommand({ connectionStatus: 1 })'
The result will look like this:
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("2af3ab0e-2197-4152-8bd0-e33efffe1464") }
MongoDB server version: 4.4.0
{
"authInfo" : {
"authenticatedUsers" : [ ],
"authenticatedUserRoles" : [ ]
},
"ok" : 1
}
A value of 1 for the ok field indicates success.
Setting up MongoDB
The MongoDB configuration file has the name mongod.conf and is located in the /etc directory. The file is in YAML format.
In most cases the default configuration settings are sufficient. However, for production environments we recommend that you comment on the security section and enable authorization as shown below:
sudo nano /etc/mongod.conf
/etc/mongod.conf
security:
authorization: enabled
The authorization parameter includes role-based access control (RBAC), which regulates user access to database resources and operations. If this option is disabled, each user will have access to all databases and perform any actions.
When editing the MongoDB configuration file, restart the mongod service for the changes to take effect:
sudo systemctl restart mongod
To find more information about the configuration options available in MongoDB 4.4, visit the configuration file options documentation page.
Create a MongoDB administrator
If you enabled MongoDB authentication, you need to create a user with administrator rights who can access and manage the MongoDB instance.
Access to the shell of mongo:
mongo
From within the MongoDB shell, enter the following command to connect to the admin database:
use admin
switched to db admin
Perform the following command to create a new user with the mongoAdmin name, changeMe password, and the userAdminAnyDatabase role:
db.createUser(
{
user: "mongoAdmin",
pwd: "changeMe",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ].
}
)
Successfully added user: {
"user" : "mongoAdmin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
Don’t forget to set a more secure password. You can name the administrative user MongoDB as you want.
After that, exit the mongo shell with the help:
quit()
To check for changes, log in to the mongo shell using the previously created administrator:
mongo -u mongoAdmin -p --authenticationDatabase admin
use admin
switched to db admin
Launch, show users and you should see information about the newly created user:
show users
{
"_id" : "admin.mongoAdmin",
"userId" : UUID("49617e41-ea3b-4fea-96d4-bea10bf87f61"),
"user" : "mongoAdmin",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
You can also try to access the mongo shell without any arguments (just type mongo) and see if you can enumerate users using the same commands as above.
Conclusion
We showed you how to install and configure MongoDB in Ubuntu 20.04. For more information on this topic please visit the MongoDB manual.
About Enteros
IT organizations routinely spend days and weeks troubleshooting production database performance issues across multitudes of critical business systems. Fast and reliable resolution of database performance problems by Enteros enables businesses to generate and save millions of direct revenue, minimize waste of employees’ productivity, reduce the number of licenses, servers, and cloud resources and maximize the productivity of the application, database, and IT operations teams.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
What Retail Tech Teams Gain from Enteros’ AI-Driven Cost Estimation and Database Optimization Platform
- 7 December 2025
- Database Performance Management
Introduction The retail industry is undergoing one of the most aggressive digital evolutions in history. From omnichannel customer experiences and real-time inventory management to personalization engines and AI-driven demand forecasting, today’s retail IT environments are powered by complex, high-volume databases and cloud ecosystems. Behind every transaction, search query, delivery update, and loyalty personalization lies a … Continue reading “What Retail Tech Teams Gain from Enteros’ AI-Driven Cost Estimation and Database Optimization Platform”
How Enteros Transforms Banking IT: Database Optimization Powered by Cloud FinOps and RevOps Intelligence
Introduction The banking sector is undergoing rapid digital modernization. Customers expect real-time transactions, instant approvals, personalized insights, mobile-first experiences, and zero downtime. At the core of this digital revolution lies one essential asset: data. Modern banks now operate massive volumes of structured and unstructured data across core banking systems, digital payments, fraud detection engines, credit … Continue reading “How Enteros Transforms Banking IT: Database Optimization Powered by Cloud FinOps and RevOps Intelligence”
How Enteros Transforms Healthcare Cost Management with AI Financial Intelligence and Database Performance Optimization
- 4 December 2025
- Database Performance Management
Introduction The healthcare sector is facing unprecedented financial and operational pressure. As medical organizations modernize their IT environments—embracing AI-driven diagnostics, telemedicine platforms, electronic health record (EHR) systems, imaging repositories, and cloud-native applications—the cost of operating these digital workloads continues to surge. At the same time, inefficiencies within databases, data pipelines, clinical software platforms, and analytics … Continue reading “How Enteros Transforms Healthcare Cost Management with AI Financial Intelligence and Database Performance Optimization”
Optimizing Retail Digital Operations: Enteros AI Platform for Accurate Cost Estimation and Superior Performance Management
Introduction The retail sector is undergoing one of the fastest digital transformations in history. From omnichannel commerce and predictive analytics to inventory automation and personalized customer experiences, today’s retail enterprises depend on complex, high-volume digital systems. These systems—spanning eCommerce platforms, databases, cloud services, POS solutions, and logistics software—process massive real-time workloads that directly influence customer … Continue reading “Optimizing Retail Digital Operations: Enteros AI Platform for Accurate Cost Estimation and Superior Performance Management”