Senior LevelMongoDB & Mongoose
How do memory limits (100MB per stage) work in Aggregation Pipelines and how does allowDiskUse handle spillover?
❓ Interview Prompt: Explain 100MB RAM cap per aggregation stage, allowDiskUse: true option, and temporary file spilling.
Aggregation pipeline stages cap RAM usage at 100MB. Passing 'allowDiskUse: true' allows WiredTiger to spill temporary sort buffers to disk.
Code Implementation Example
typescript
import { OrderModel } from './models/Order';
async function executeLargeAggregation() {
return await OrderModel.aggregate([
{ $sort: { totalAmount: -1 } }
]).allowDiskUse(true); // Spills to disk if RAM exceeds 100MB!
}💡Executing large aggregations with allowDiskUse(true).
🎯 Interview Key Takeaway
Pass allowDiskUse(true) on large aggregation pipelines to prevent 100MB RAM memory limit crashes.
#allowDiskUse#Aggregation#Memory Limits#Senior
Back to all MongoDB & Mongoose Questions→