How to Install MongoDB on Ubuntu 22.04 | Step-by-Step Guide to Using MongoDB [With Examples]
Published: 2023-11-15 07:19:42

==> official blogs

## 1.
 https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/#std-label-install-mdb-community-ubuntu

## 2. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9lqkdncp1zzwlmvrpf4b.png)

=>
It looks like you have downloaded the MongoDB Compass Debian package (`mongodb-compass_1.40.4_amd64.deb`). To install MongoDB Compass on a Debian-based Linux system (such as Ubuntu), you can use the following steps:

1. Open a terminal.

2. Navigate to the directory where the downloaded `.deb` file is located. For example, if it's in the Downloads folder, you can use the following command:

   ```bash
   cd ~/Downloads
   ```

3. Install MongoDB Compass using the `dpkg` package manager. Replace `mongodb-compass_1.40.4_amd64.deb` with the actual filename if it's different:

   ```bash
   sudo dpkg -i mongodb-compass_1.40.4_amd64.deb
   ```

4. If there are any missing dependencies, you might see an error. To resolve dependencies, run the following command:

   ```bash
   sudo apt-get install -f
   ```

   This command will attempt to fix missing dependencies.

5. After the installation is complete, you can launch MongoDB Compass from the terminal or find it in your application menu.

   ```bash
   mongodb-compass
   ```

   Alternatively, you can launch it from the application menu or using the Dash.

Please note that you may need to have administrative privileges (`sudo`) to install packages. If you encounter any issues during the installation, the error messages should provide information about missing dependencies or other problems.

If you face any specific errors or issues during the installation, feel free to share the details, and I'll do my best to assist you.

## 3.
**The Smartest IDE for MongoDB
**
https://nosqlbooster.com/
---

best blogs==> https://www.cherryservers.com/blog/install-mongodb-ubuntu-22-04
---
https://www.youtube.com/watch?v=I2sjJqFTfWY

```
sudo apt-get install gnupg curl
```

---

```
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
   --dearmor
```

---

```
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
```

---

```
ls -l /etc/apt/sources.list.d/
```

---
```
sudo apt-get update

```

---
```
sudo apt-get install -y mongodb-org
```

---


Certainly! Here are the commands formatted in Markdown code blocks:

```bash
# 1. Start MongoDB.
# Start the mongod process
sudo systemctl start mongod

# If Unit not found error, run the following command:
sudo systemctl daemon-reload

# Retry the start command
sudo systemctl start mongod

# 2. Verify that MongoDB has started successfully.
sudo systemctl status mongod

# Optionally enable MongoDB to start on system reboot
sudo systemctl enable mongod

# 3. Stop MongoDB.
# Stop the mongod process
sudo systemctl stop mongod

# 4. Restart MongoDB.
# Restart the mongod process
sudo systemctl restart mongod

# Check process status and logs for errors
# 5. Begin using MongoDB.
# Start a mongosh session
mongosh

# For more connection options, refer to mongosh documentation
# MongoDB provides Getting Started Guides for different driver editions
# See the Start Developing with MongoDB documentation for driver-specific details
```


```
mongod --version
```
```
sudo systemctl status mongod
```

```
sudo systemctl start mongod
```

```
sudo systemctl status mongod
```

```
sudo ss -pnltu | grep 27017
```

---
```
sudo systemctl enable mongod
```

## Step 3: Create MongoDB database and user

```
mongosh
```

```bash
With the Admin user in place, the next step is to enable authentication. For this, exit the MongoDB shell and open the mongod.conf file.

sudo nano /etc/mongod.conf
Scroll down and find the security section. Uncomment it, add the authorization directive, and set it to enabled.


security:
    authorization: enabled
Note that the authorization parameter is indented while security has no space at the beginning.


```