Q56 [Scenario]: You need to rename a field across 50 million documents in production without downtime. How do you execute this?
Do NOT execute a blocking $rename update on 50M documents at once (locks memory and replication).
- Update application code to handle both old and new field names via Mongoose virtuals or getters.
- Write new data using the new field name.
- Run a background script processing documents in small batched cursor chunks using
$setand$unsetduring off-peak hours.
Key Takeaways
Avoid single monolithic updates on massive production collections.
Execute chunked background updates using cursor pagination.
Knowledge Check
Why is running db.collection.updateMany({}, { $rename: ... }) dangerous on a 50M document production table?