Intermediate LevelMongoDB & Mongoose
How do you monitor WiredTiger cache size using db.serverStatus()?
❓ Interview Prompt: Explain db.serverStatus(), monitoring wiredTiger.cache, tracked dirty bytes, and dirty page eviction rates.
Running 'db.serverStatus().wiredtiger.cache' tracks active memory usage, dirty page bytes, and cache eviction rates to prevent memory thrashing.
Code Implementation Example
typescript
import mongoose from 'mongoose';
async function checkWiredTigerCache() {
const adminDb = mongoose.connection.db!.admin();
const status = await adminDb.command({ serverStatus: 1 });
console.log('Cache Usage (MB):', (status.wiredTiger.cache['bytes currently in the cache'] / 1024 / 1024).toFixed(2));
}💡Monitoring WiredTiger memory cache statistics via serverStatus.
🎯 Interview Key Takeaway
Monitor WiredTiger cache metrics with serverStatus to ensure active working sets fit in RAM.
#WiredTiger#serverStatus#Cache Metrics#Intermediate
Back to all MongoDB & Mongoose Questions→