use admin
db.createUser({
user: "appuser",
pwd: "strong-password",
roles: [{ role: "readWrite", db: "appdb" }]
})Create users in the appropriate database, often `admin` for centralized management.
Create users, grant roles, inspect server status, and run the most common administrative commands in MongoDB.
Basic authentication and role-management workflows.
use admin
db.createUser({
user: "appuser",
pwd: "strong-password",
roles: [{ role: "readWrite", db: "appdb" }]
})Create users in the appropriate database, often `admin` for centralized management.
db.getUsers()Useful when auditing local database users.
db.grantRolesToUser("appuser", [{ role: "dbAdmin", db: "appdb" }])Roles can be layered as responsibilities change.
db.changeUserPassword("appuser", "new-strong-password")Routine credential rotation is easier when you know the exact shell command.
db.dropUser("appuser")Useful during environment cleanup or credential revocation.
Operational commands for quick diagnostics.
Inspect a detailed server-status document.
db.adminCommand({ serverStatus: 1 })Returns deep operational detail; it is often used for diagnostics, monitoring, and troubleshooting.
See active operations on the server.
db.currentOp()Helpful when tracking down long-running operations or lock contention.
db.killOp(12345)Use carefully after confirming the operation is safe to terminate.
db.adminCommand({ ping: 1 })A lightweight connectivity check.
db.adminCommand({ buildInfo: 1 })Useful when you need to confirm the running server version and build details.