MongoDB is a popular open-source NoSQL database that provides high performance, high availability, and easy scalability. In this guide, we will show you how to install and configure MongoDB on Ubuntu 18.04 LTS. Whether you're using a Windows VPS UK or another server provider, MongoDB is a flexible solution for managing large amounts of data.

Prerequisites

Before you begin, ensure you have the following:

Step 1: Import the MongoDB Repository

MongoDB is not available in the default Ubuntu repositories, so you will need to add the official MongoDB repository. First, import the GPG key:

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

Next, add the MongoDB repository:

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list

Step 2: Install MongoDB

Once the repository is added, update the package list and install MongoDB:

sudo apt update
sudo apt install -y mongodb-org

Step 3: Start and Enable MongoDB

After installation, start the MongoDB service and enable it to start on boot:

sudo systemctl start mongod
sudo systemctl enable mongod

Step 4: Verify MongoDB Installation

Verify that MongoDB is running by checking its status:

sudo systemctl status mongod

You should see output indicating that MongoDB is active and running.

Step 5: Access the MongoDB Shell

To start using MongoDB, you can access the MongoDB shell by running:

mongo

This will bring you to the MongoDB shell, where you can run database commands.

Step 6: Basic MongoDB Commands

Here are a few basic commands to help you get started with MongoDB:

    • Create a new database:
use mydatabase
    • Create a collection and insert data:
db.mycollection.insert({ name: "John", age: 30 })
    • Find data in a collection:
db.mycollection.find()

Step 7: Secure MongoDB (Optional)

By default, MongoDB allows connections only from localhost. If you want to enable remote access, you need to edit the MongoDB configuration file:

sudo nano /etc/mongod.conf

Find the line that starts with bindIp and add your server’s IP address:

bindIp: 127.0.0.1, your-server-ip

After making this change, restart MongoDB:

sudo systemctl restart mongod

Conclusion

By following these steps, you have successfully installed and configured MongoDB on Ubuntu 18.04 LTS. Whether you're hosting your MongoDB database on a Windows VPS UK, Windows VPS Italy, or another Windows Virtual Private Server Hosting solution, MongoDB offers a scalable and flexible database solution for modern applications.

Cette réponse était-elle pertinente? 0 Utilisateurs l'ont trouvée utile (0 Votes)