Linux MongoDB Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux MongoDB Guide
Complete beginner-friendly guide to MongoDB on Linux, covering Arch Linux, CachyOS, and other distributions including installation, configuration, and database management.
Table of Contents
MongoDB Installation
Install MongoDB
Arch/CachyOS:
# Install MongoDB
yay -S mongodb-bin
# Or community edition
yay -S mongodb
Debian/Ubuntu:
# Add MongoDB repository
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt update
sudo apt install mongodb-org
Fedora:
# Add MongoDB repository
# Download from mongodb.com
Enable Service
Start MongoDB:
# Enable and start service (recommended method)
sudo systemctl enable --now mongodb
# Check status
systemctl status mongodb
MongoDB Configuration
MongoDB Shell
Connect to MongoDB:
# Launch MongoDB shell
mongosh
# Or mongo (older versions)
mongo
Create Database
Create database:
// In MongoDB shell
use mydb
// Insert document
db.collection.insertOne({name: "example"})
MongoDB Usage
Basic Operations
CRUD operations:
// Create
db.collection.insertOne({key: "value"})
// Read
db.collection.find()
// Update
db.collection.updateOne({key: "value"}, {$set: {new: "data"}})
// Delete
db.collection.deleteOne({key: "value"})
Troubleshooting
MongoDB Not Starting
Check service:
# Check status
systemctl status mongodb
# Check logs
journalctl -u mongodb
# Check data directory
ls -la /var/lib/mongodb
Summary
This guide covered MongoDB installation, configuration, and usage for Arch Linux, CachyOS, and other distributions.
Next Steps
- Database Servers - Database setup
- Development Environment - Development
- MongoDB: https://www.mongodb.com/
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.