MongoDB is a document-oriented NoSQL database that stores data as BSON (Binary JSON) documents rather than rows in tables. This schema-flexible approach makes MongoDB ideal for applications with rapidly evolving data models, hierarchical data (product catalogs, user profiles, content management), geospatial queries, and high-volume write workloads. MongoDB 7.x introduced significant improvements including multi-document ACID transactions, time-series collections, clustered collections for range queries, and improvements to the aggregation pipeline. RHEL 9’s official repositories do not include MongoDB; it must be installed from MongoDB’s official YUM repository. This guide covers adding the MongoDB repository, installing MongoDB 7 Community Edition on RHEL 9, configuring authentication, creating databases and users, and basic operational tasks.

Prerequisites

  • RHEL 9 with sudo/root access
  • At least 4 GB RAM for production use

Step 1 — Add the MongoDB Repository

# /etc/yum.repos.d/mongodb-org-7.0.repo
cat > /etc/yum.repos.d/mongodb-org-7.0.repo <<'EOF'
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/9/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-7.0.asc
EOF

Step 2 — Install MongoDB

dnf install -y mongodb-org
systemctl enable --now mongod
systemctl status mongod

mongod --version

Step 3 — Enable Authentication

# First connect without auth to create the admin user
mongosh
// Inside mongosh
use admin
db.createUser({
  user: "admin",
  pwd: "StrongAdminPassword123!",
  roles: [{ role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase"]
})
exit
# Enable auth in /etc/mongod.conf
security:
  authorization: enabled
systemctl restart mongod

Step 4 — Create a Database and Application User

mongosh -u admin -p StrongAdminPassword123! --authenticationDatabase admin
use myapp
db.createUser({
  user: "myapp_user",
  pwd: "AppPassword456!",
  roles: [{ role: "readWrite", db: "myapp" }]
})

// Insert a test document
db.test.insertOne({ name: "RHEL 9", type: "OS", year: 2022 })
db.test.findOne()

exit

Step 5 — Configure mongod.conf

# /etc/mongod.conf
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
  timeStampFormat: iso8601-utc

storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
  wiredTiger:
    engineConfig:
      cacheSizeGB: 1    # Set to 50% of available RAM

net:
  port: 27017
  bindIp: 127.0.0.1    # Change to 0.0.0.0 if remote access needed

security:
  authorization: enabled

operationProfiling:
  slowOpThresholdMs: 100   # Log operations slower than 100ms
systemctl restart mongod

Step 6 — Open Firewall for Remote Access (Optional)

# Only expose MongoDB to specific IPs — never expose directly to the internet
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port port="27017" protocol="tcp" accept'
firewall-cmd --reload

Conclusion

MongoDB 7 Community Edition on RHEL 9 provides a flexible, document-oriented database well-suited for applications with variable-structure data, nested documents, and horizontal scaling requirements. Enabling authentication immediately after installation and binding to 127.0.0.1 by default are critical security steps. The WiredTiger cache size should be set to 50% of available RAM for optimal performance.

Next steps: How to Install Redis on RHEL 9, How to Install PostgreSQL on RHEL 9, and How to Install Elasticsearch on RHEL 9.