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).

  1. Update application code to handle both old and new field names via Mongoose virtuals or getters.
  2. Write new data using the new field name.
  3. Run a background script processing documents in small batched cursor chunks using $set and $unset during 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?