How To Install MongoDB on Ubuntu 22.04
In this guide, we will explain how to install MongoDB on Ubuntu 22.04, providing a scalable NoSQL database solution for your applications and data management.
Last updated
In this guide, we will explain how to install MongoDB on Ubuntu 22.04, providing a scalable NoSQL database solution for your applications and data management.
Last updated
MongoDB is an open-source NoSQL database that uses a flexible, document-oriented data model. Unlike traditional relational databases that use tables and rows, MongoDB stores data in JSON-like documents, which can have varied structures. This makes it highly adaptable and suitable for applications requiring scalable, high-performance, and flexible data storage solutions.
Launch the Ubuntu 22.04 instance on Neevcloud
Access the server using SSH
First, ensure your package list is up to date to avoid any issues with outdated packages
Execute the given command to install the MongoDB package.
To install the most recent MongoDB package, you need to add the MongoDB package repository to your sources list file on Ubuntu.
After this next. add MongoDB APT repository to the /etc/apt/sources.list.d/
directory.
Next, include the MongoDB source list file in the /etc/apt/sources.list.d/
directory, which consists of a lone line stating
Add all repositories first, then update the packages
Now, proceed to install the mongodb-org meta-package, which includes MongoDB.
After installation, the MongoDB service starts and enables
Enable it to start when the system rebooted
To verify the database's status, make sure the server is actively listening on port 27017.
Verify that the database service is active and running. Run the following command
Make sure the MongoDB instance is up and set up for remote access, then learn how to create a database and a user in MongoDB.
By default, installation results in the creation of three databases. This includes admin, config, and local.
To make a database, execute the use
command with the name of the database. For example, to create a database named test_db
, run the command
To verify the database you are using, execute the db
command. In this scenario, the output will be test_db
.
MongoDB offers various shell techniques to control your database. The db.createUser
function enables the creation of a new user within a database.
This is how you can create a user name test_user
with read-and-write roles for the test_db
database.
You can list the users created using the db.getUsers()
command.
Alternatively, run the command