Using Database Commands
1. Running Admin Commands
db.adminCommand({ shutdown: 1 });
2. Running Database Commands
| Method | Detail |
| db.runCommand(cmd) | Generic command runner |
| db.adminCommand(cmd) | Runs against admin DB |
3. Using listDatabases Command
db.adminCommand({ listDatabases: 1, nameOnly: true });
4. Using listCollections Command
db.runCommand({ listCollections: 1, filter: { name: /^orders/ } });
5. Using serverStatus Command
| Aspect | Detail |
| Output size | Large; pass section selectors |
| Example | db.serverStatus({connections:1, opcounters:1}) |
6. Using replSetGetStatus Command
| Output | Detail |
| members[] | State, optime, lastHeartbeat |
| myState | Self role (1=primary, 2=secondary) |
7. Using dbStats Command
| Field | Detail |
| collections / objects | Counts |
| dataSize / storageSize | Logical vs on-disk |
| indexSize | Total index size |
8. Using collStats Command
db.runCommand({ collStats: "orders", scale: 1024 });
9. Using compact Command
| Aspect | Detail |
| Effect | Defragment WT files, reclaim space |
| Lock | Blocks writes on target collection |
| Practice | Run on secondary, then step down/restart |
10. Using buildInfo Command
| Field | Detail |
| version | MongoDB version |
| modules | Enterprise/community |
| openssl | TLS support details |
11. Using connectionStatus Command
| Field | Detail |
| authenticatedUsers | Current users on connection |
| authenticatedUserRoles | Effective roles |