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
From Data to Delivery: How Enteros Transforms D2C Brands Through Database Performance and Cloud FinOps
- 6 October 2025
- Database Performance Management
Introduction In the fast-evolving world of Direct-to-Consumer (D2C) brands, agility and performance are everything. D2C businesses thrive on personalization, speed, and customer trust — all of which depend on how efficiently data flows through their systems. Behind every product recommendation, every smooth checkout, and every on-time delivery is a complex network of databases, cloud infrastructure, … Continue reading “From Data to Delivery: How Enteros Transforms D2C Brands Through Database Performance and Cloud FinOps”
How Enteros AI Performance and Data Lake Optimization Are Powering Innovation in the Fashion Industry
Introduction The fashion industry, once ruled by instinct and creativity alone, is now undergoing a seismic transformation driven by data and artificial intelligence (AI). From forecasting trends to managing supply chains and customer experiences, data-driven insights are redefining how fashion brands operate. Central to this digital shift is the use of AI-driven performance management and … Continue reading “How Enteros AI Performance and Data Lake Optimization Are Powering Innovation in the Fashion Industry”
When Booking Systems Freeze: The Hidden IT Challenge Behind Aviation Disruptions
Behind every on-time departure, there’s an invisible network of data systems working in sync.But when that synchronization breaks — even for a few seconds — the result can ground entire fleets. The Hidden Digital Backbone of Aviation Today’s airlines and airport operators depend on complex ecosystems that process millions of real-time transactions per minute: Flight … Continue reading “When Booking Systems Freeze: The Hidden IT Challenge Behind Aviation Disruptions”
How Enteros AIOps and Generative AI Are Powering the Cloud Center of Excellence for Modern Banking
- 5 October 2025
- Database Performance Management
Introduction The modern banking industry is being reshaped by digital innovation. Artificial Intelligence (AI), automation, and cloud computing are no longer optional — they are the driving forces behind operational efficiency, customer personalization, and financial growth. Amid this technological transformation, banks are building Cloud Centers of Excellence (CCoE) to unify their cloud strategies, improve governance, … Continue reading “How Enteros AIOps and Generative AI Are Powering the Cloud Center of Excellence for Modern Banking”