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 Drives Growth in Technology Platforms: Enteros AI SQL, Database Management, and Performance Metrics
- 11 March 2026
- Database Performance Management
Introduction Technology platforms have become the backbone of the modern digital economy. From SaaS products and cloud-native applications to AI-powered analytics and global digital marketplaces, technology enterprises rely on robust infrastructure to deliver reliable, scalable services to millions of users. At the center of these digital ecosystems lies one of the most critical components of … Continue reading “What Drives Growth in Technology Platforms: Enteros AI SQL, Database Management, and Performance Metrics”
How to Modernize Fashion Data Platforms with Enteros Database Management and Generative AI
Introduction The global fashion industry has transformed dramatically in the digital era. Once driven primarily by seasonal collections and physical retail, fashion brands today rely heavily on digital platforms, e-commerce marketplaces, data analytics, and AI-powered customer experiences. From trend forecasting and inventory management to real-time customer engagement, modern fashion businesses are powered by complex data … Continue reading “How to Modernize Fashion Data Platforms with Enteros Database Management and Generative AI”
How Banking Platforms Achieve Accurate Cost Estimation with Enteros GenAI and Cloud Cost Attribution
- 10 March 2026
- Database Performance Management
Introduction The banking industry is undergoing one of the most significant technological transformations in its history. Digital banking platforms, mobile payment systems, AI-powered fraud detection, and real-time financial analytics are now fundamental components of modern banking operations. These innovations rely on powerful cloud infrastructure and highly optimized databases to process millions of financial transactions every … Continue reading “How Banking Platforms Achieve Accurate Cost Estimation with Enteros GenAI and Cloud Cost Attribution”
From Performance Monitoring to Growth Intelligence: Enteros AIOps for Technology Enterprises
Introduction Technology enterprises are operating in an era where digital platforms determine market success. Software products, cloud platforms, SaaS applications, data analytics tools, and AI-powered systems are the backbone of modern businesses. Behind these digital services lies an intricate ecosystem of databases, cloud infrastructure, and applications that must operate at peak performance. For technology companies, … Continue reading “From Performance Monitoring to Growth Intelligence: Enteros AIOps for Technology Enterprises”