Using Database Commands

1. Running Admin Commands

db.adminCommand({ shutdown: 1 });

2. Running Database Commands

MethodDetail
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

AspectDetail
Output sizeLarge; pass section selectors
Exampledb.serverStatus({connections:1, opcounters:1})

6. Using replSetGetStatus Command

OutputDetail
members[]State, optime, lastHeartbeat
myStateSelf role (1=primary, 2=secondary)

7. Using dbStats Command

FieldDetail
collections / objectsCounts
dataSize / storageSizeLogical vs on-disk
indexSizeTotal index size

8. Using collStats Command

db.runCommand({ collStats: "orders", scale: 1024 });

9. Using compact Command

AspectDetail
EffectDefragment WT files, reclaim space
LockBlocks writes on target collection
PracticeRun on secondary, then step down/restart

10. Using buildInfo Command

FieldDetail
versionMongoDB version
modulesEnterprise/community
opensslTLS support details

11. Using connectionStatus Command

FieldDetail
authenticatedUsersCurrent users on connection
authenticatedUserRolesEffective roles