
{{ $('Map tags to IDs').item.json.title }}
Getting Started with MongoDB on Ubuntu
MongoDB is a popular NoSQL database that provides high performance, high availability, and easy scalability. This tutorial will guide you through the steps of installing and setting up MongoDB on an Ubuntu system.
Prerequisites
- A system running Ubuntu (preferably 20.04 or later).
- Root or sudo privileges to install packages.
1. Import the MongoDB Public Key
First, you need to import the MongoDB GPG public key to ensure package authenticity:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
2. Create a List File for MongoDB
Next, create a list file for MongoDB. Use the following command to create a new source list:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/multiverse amd64 packages" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
Replace focal
with your Ubuntu version (e.g., bionic
for 18.04).
3. Update Package Index
Update the local package index to include the MongoDB packages:
sudo apt update
4. Install MongoDB
Install the latest version of MongoDB:
sudo apt install mongodb-org -y
This command installs the MongoDB server and client along with the necessary dependencies.
5. Starting MongoDB
After installation, start the MongoDB service with the following command:
sudo systemctl start mongod
To enable MongoDB to start automatically on boot, run:
sudo systemctl enable mongod
6. Checking MongoDB Status
You can check if MongoDB is running by using:
sudo systemctl status mongod
You should see an output indicating that the MongoDB service is active (running).
7. Accessing the MongoDB Shell
To interact with your MongoDB database, open the MongoDB shell by running:
mongo
This will launch the MongoDB shell where you can execute database commands.
8. Creating and Managing Databases
Once in the MongoDB shell, you can create a new database using:
use my_new_database
To insert data, use:
db.my_collection.insert({ name: "example", type: "demo" })
9. Stopping MongoDB
To stop the MongoDB service, use:
sudo systemctl stop mongod
10. Conclusion
You have successfully installed and set up MongoDB on Ubuntu. This NoSQL database is powerful for handling various data types and can scale easily as your application grows. Explore more about MongoDB’s features to fully utilize its capabilities!