How to Install MongoDB on Ubuntu 22.04

MongoDB is a real popular way to store and manage lots of unstructured or semi-structured data. It’s a type of database that focuses on documents, so you can be more flexible with the structure of your data than you could with a more traditional database.

A lot of people use MongoDB in web and mobile apps, and other places where you need to move and work with data really fast. It can handle huge amounts of data without slowing down, and it can work with different kinds of data models and languages.

Some of the reasons why people like MongoDB are that it’s good at handling really complicated data, it’s flexible when it comes to indexing, and it can handle being distributed across lots of different machines. And there are lots of tools and ways to work with data in MongoDB, which makes it a good choice for people who are building apps or studying data.

We’ll show you how to install MongoDB on Ubuntu 22.04, so you can get started with this powerful database tool. Our article will walk you through the entire process, including setting up and configuring MongoDB to work with your system. Whether you’re an experienced developer or new to MongoDB, keep reading to learn how to get up and running with this flexible database system on Ubuntu 22.04.

Read: How to create a user in MongoDB

Installing Mongodb on Ubuntu 22.04

To get started with Mongodb installation, open up the terminal and run the command provided below.

sudo wget -qO – https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add –

Next , execute the command:

sudo echo “deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

To update your repositories, invoke the command :

sudo apt-get update -y

Read: How to install MongoDB on Ubuntu 20.04 or 18.04

Next, run the command :

sudo wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb

And then :

sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb

Finally, to install Mongodb, run the command :

sudo apt-get install -y mongodb-org

Install Mongodb Ubuntu

Read: A Comprehensive Guide to Installing GCC on Ubuntu 22.04

After the installation finishes, you’ll likely see a message that looks like this:

Read: How to Create and Manipulate SQL Database with Python

To check the status of the Mongodb status, execute the command:

sudo systemctl status mongod.service

To start the Mongodb service, run the command:

sudo systemctl start mongod

Now you can check the status again :

sudo systemctl status mongod.service

To make sure MongoDB is always available when you start your computer, you’ll need to enable the MongoDB service to run automatically at startup. This can be done by running the command:

sudo systemctl enable mongod.service

Now in order to connect to Mongodb , invoke the following command:

sudo mongosh

Read: How to Install MySQL Workbench on Ubuntu 22.04

Now you should be able to start working with Mongodb.

For instance, to create a mongodb database called myDatabase , run the command :

To insert a collection of employees, execute :

MongoDB create a collection

After creating the collection, you can add new documents to it by utilizing the insertOne() or insertMany() methods. To illustrate, suppose you want to include a document with “John Doe” as the name, “Manager” as the title, and “Sales” as the department, you can enter the subsequent command:

You have the flexibility to add any number of fields to each document, and you can modify or delete documents with the help of different methods provided by MongoDB.

Read: How to install Node.js on Linux/Ubuntu

How to uninstall mongodb

In order to remove Mongodb on Ubuntu, run the command below:

sudo apt remove mongodb-org

And finally, execute:

sudo apt autoremove

Conclusion

Setting up MongoDB on Ubuntu 22.04 is an uncomplicated process that can be completed in just a few easy steps. With the help of the guidelines presented in this article, you will be able to effortlessly install and set up MongoDB on your system. Whether you are a developer who wants to integrate MongoDB into your projects or simply someone who wants to learn more about this versatile database system, we hope that this article has given you the direction and knowledge you need to begin.

 


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Marianne elanotta

Marianne is a graduate in communication technologies and enjoys sharing the latest technological advances across various fields. Her programming skills include Java OO and Javascript, and she prefers working on open-source operating systems. In her free time, she enjoys playing chess and computer games with her two children.

Leave a Reply