MongoDB Installation Guide
This guide provides all the key information and getting-started instructions after a successful MongoDB installation via DeploySage-CLI.
Getting Started
You can start interacting with your MongoDB instance using the MongoDB Shell (mongosh).
# Connect to the MongoDB server
mongosh
# Show all databases
show dbs
# Switch to a database (creates it if it doesn't exist)
use myNewDatabase
# Insert a document into a collection
db.myCollection.insertOne({ name: "test", value: 123 })
# Find all documents in a collection
db.myCollection.find()
Service Management
Manage the MongoDB service (mongod) using standard systemctl commands.
# Start the MongoDB service
sudo systemctl start mongod
# Stop the service
sudo systemctl stop mongod
# Check the service status
sudo systemctl status mongod
# View real-time logs
sudo journalctl -u mongod -f
Enabling Access Control
Follow these steps to secure your MongoDB installation. A detailed guide has also been created at /root/mongodb_security_guide.md.
use admin
db.createUser({
user: "myAdmin",
pwd: passwordPrompt(), // or a strong password string
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
})
security:
authorization: enabled
sudo systemctl restart mongod