<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/hgvzh8imk" -->

---
title: How I Corrupted 2 Million+ DB Records in Prod | daily.dev
description: A migration script to encrypt sensitive user data in MongoDB corrupted over 2 million records by accidentally wiping out unencrypted fields. The bug occurred...
canonical: https://daily.dev/posts/hgvzh8imk
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How I Corrupted 2 Million+ DB Records in Prod | daily.dev
og:description: A migration script to encrypt sensitive user data in MongoDB corrupted over 2 million records by accidentally wiping out unencrypted fields. The bug occurred...
og:url: https://daily.dev/posts/hgvzh8imk
og:image: https://api.daily.dev/og/posts/hgvzh8Imk.png
og:image:alt: Post cover image
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How I Corrupted 2 Million+ DB Records in Prod

**[DevOps Daily](https://daily.dev/sources/devopsdaily)** · [@qwertydiy](https://daily.dev/qwertydiy) · 0 upvotes · 0 comments

## Summary

A migration script to encrypt sensitive user data in MongoDB corrupted over 2 million records by accidentally wiping out unencrypted fields. The bug occurred because MongoDB's $set operation replaces entire nested objects rather than merging properties. Running the migration twice resulted in both encrypted and unencrypted fields being set to undefined, causing queries to return millions of records and spike memory usage in Kubernetes pods. Recovery required restoring a database backup from before the migration and cross-referencing with Redshift data to identify users who registered during the incident window.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=fH4i2Q78jVo>

## Similar posts on daily.dev

- [Sort This Out](https://daily.dev/posts/sort-this-out-0cx7s10qv) · The Daily WTF · 0 upvotes · 0 comments
- [The Cost of Not Knowing MongoDB \(Part 1\)](https://daily.dev/posts/the-cost-of-not-knowing-mongodb-part-1--7e2zqp5yy) · Foojay.io · 3 upvotes · 0 comments
- [MongoBleed explained simply](https://daily.dev/posts/mongobleed-explained-simply-fyjdy2snj) · Lobsters · 2 upvotes · 0 comments

---

Tags: [#kubernetes](https://daily.dev/tags/kubernetes), [#database](https://daily.dev/tags/database), [#mongodb](https://daily.dev/tags/mongodb), [#encryption](https://daily.dev/tags/encryption)

[View this post on daily.dev](https://daily.dev/posts/hgvzh8imk)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/hgvzh8imk","headline":"How I Corrupted 2 Million+ DB Records in Prod","text":"Shared: How I Corrupted 2 Million+ DB Records in Prod","url":"https://daily.dev/posts/hgvzh8imk","datePublished":"2026-01-12T16:16:20.426Z","dateModified":"2026-01-12T16:16:20.429Z","author":{"@type":"Person","name":"Rene Yibowei","url":"https://daily.dev/qwertydiy","image":"https://media.daily.dev/image/upload/s--QlvtioAW--/f_auto/v1746524446/avatars/avatar_aTUl3chxFyPngKtboGisL","description":"Secondary School Student doing the Full Stack with Linux, currently learning Data Science","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":19280}},"image":"https://media.daily.dev/image/upload/s--qPvKM23u--/f_auto/v1722860399/public/Placeholder%2009","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"sharedContent":{"@type":"WebPage","url":"https://api.daily.dev/r/UKwJQCYbS"},"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/devopsdaily","name":"DevOps Daily"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"DevOps Daily","item":"https://daily.dev/squads/devopsdaily"},{"@type":"ListItem","position":3,"name":"How I Corrupted 2 Million+ DB Records in Prod"}]}
```

