Categories: TutorialsUbuntu

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.

Sponsored

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

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

Sponsored

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 on Ubuntu 18.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.

 

The post How to Install MongoDB on Ubuntu 22.04 appeared first on net2.

Ubuntu Server Admin

Recent Posts

Building optimized LLM chatbots with Canonical and NVIDIA

The landscape of generative AI is rapidly evolving, and building robust, scalable large language model…

6 hours ago

Unlocking Edge AI: a collaborative reference architecture with NVIDIA

The world of edge AI is rapidly transforming how devices and data centers work together.…

6 hours ago

How to Install and Use Zig Programming Language on Ubuntu or Debian Linux

In this article, we will see how to install and use zig programming language on…

9 hours ago

Linux Sed Tutorial: Learn Text Editing with Syntax and Examples

This article was adapted from its original version on NixCraft. Sed is an acronym for…

15 hours ago

How to Fix VMware’s “Could not open /dev/vmmon” Error on Ubuntu

You’ve recently installed VMware Workstation on your Ubuntu system and encountered the frustrating “Could not…

23 hours ago

How to Fix Ubuntu 404 Errors While Fetching Dependencies

Have you ever found yourself staring at a terminal full of 404 errors while trying…

23 hours ago