<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-i-corrupted-2-million-db-records-in-prod-ukwjqcybs" -->

---
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/how-i-corrupted-2-million-db-records-in-prod-ukwjqcybs
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/how-i-corrupted-2-million-db-records-in-prod-ukwjqcybs
og:image: https://api.daily.dev/og/posts/UKwJQCYbS.png
og:image:alt: How I Corrupted 2 Million+ DB Records in Prod
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

**[Kiki's Bytes ](https://daily.dev/sources/kikisbytes)** · 7 min read · 155 upvotes · 13 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>

## Community discussion

Top comments from developers on daily.dev.

**@jmichael** · 18 upvotes

> ![image](https://media.daily.dev/image/upload/s--BW_otbDZ--/f_auto/v1768592153/ugc/content_1131b502-f17d-488f-828a-bd1c97366f41?_a=BAMAMiiu0)

**@sbecker** · 17 upvotes

> wow, thanks for sharing, sounds like a nightmare.
> i guess we cannot avoid these mistakes 100% unless not doing the work.
>
> Those who do things will also go wrong.
> The trick, like you mentioned, is to own our mistakes, take responsibility and to use it as opportunity to learn and grow.

**@hassanirfan527** · 16 upvotes

> When I read the title, I was terrified, and I was like: "This guy is cooked", but tis kinda fun isn't it? Like, in future, whenever you will remember your best memories, you'd remember: "Once, I corrupted 2 million db records, lol"

**@grahampayne** · 14 upvotes

> I work a lot with SQL server and do a lot of backend work. I made quite a few mistakes, and broke a couple of DB's myself, before I got to workable process to eliminate most of the errors I made.
> 1. Always test on a QA enviroment first.
> 2.  Read your sql scripts 7 times. It takes longer to fix an error than to read that script 7 times.
> 3. Always have a rollback script for the work to be done. If there is an error you can easily revert and fix.
> 4. If you are tired of testing, you know you are ready to push to production.
> 5. Even if you do all these things above you will still make mistakes as...

**@stuartgreig** · 1 upvotes

> The road to senior developer is littered with mistakes you made on the way. The mistakes teach you a lot more than the successes.

## Similar posts on daily.dev

- [Sort This Out](https://daily.dev/posts/sort-this-out-0cx7s10qv) · The Daily WTF · 0 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/how-i-corrupted-2-million-db-records-in-prod-ukwjqcybs)

```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":"TechArticle","headline":"How I Corrupted 2 Million+ DB Records in Prod","url":"https://daily.dev/posts/how-i-corrupted-2-million-db-records-in-prod-ukwjqcybs","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-i-corrupted-2-million-db-records-in-prod-ukwjqcybs"},"datePublished":"2026-01-12T14:20:46.151Z","dateModified":"2026-01-12T14:26:52.067Z","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...","image":"https://i.ytimg.com/vi/fH4i2Q78jVo/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/fH4i2Q78jVo/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Kiki's Bytes ","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Kiki's Bytes ","logo":"https://media.daily.dev/image/upload/s--GJQRfY13--/f_auto/v1752677336/logos/kikisbytes","url":"https://daily.dev/sources/kikisbytes"},"commentCount":13,"discussionUrl":"https://daily.dev/posts/how-i-corrupted-2-million-db-records-in-prod-ukwjqcybs","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":155},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":13}],"keywords":"kubernetes,database,mongodb,encryption","timeRequired":"PT7M","video":{"@type":"VideoObject","name":"How I Corrupted 2 Million+ DB Records in Prod","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...","thumbnailUrl":"https://i.ytimg.com/vi/fH4i2Q78jVo/sddefault.jpg","uploadDate":"2026-01-12T14:20:46.151Z","duration":"PT7M","url":"https://api.daily.dev/r/UKwJQCYbS","embedUrl":"https://www.youtube.com/embed/fH4i2Q78jVo"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Kiki's Bytes ","item":"https://daily.dev/sources/kikisbytes"},{"@type":"ListItem","position":3,"name":"How I Corrupted 2 Million+ DB Records in Prod"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-i-corrupted-2-million-db-records-in-prod-ukwjqcybs","comment":[{"@type":"Comment","text":"","datePublished":"2026-01-16T19:36:07.849Z","url":"https://daily.dev/posts/UKwJQCYbS#c-JS0nWffsn","author":{"@type":"Person","name":"JMichael","url":"https://daily.dev/jmichael","image":"https://media.daily.dev/image/upload/s--Yj8tXNc4--/f_auto/v1768335072/avatars/avatar_dSlgvp69V3SOg2MWOSFlr?_a=BAMAMiZW0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":18}},{"@type":"Comment","text":"wow, thanks for sharing, sounds like a nightmare.\ni guess we cannot avoid these mistakes 100% unless not doing the work.\nThose who do things will also go wrong.\nThe trick, like you mentioned, is to own our mistakes, take responsibility and to use it as opportunity to learn and grow.","datePublished":"2026-01-13T07:36:22.538Z","url":"https://daily.dev/posts/UKwJQCYbS#c-ySO35pb5y","author":{"@type":"Person","name":"Sivan","url":"https://daily.dev/sbecker","image":"https://media.daily.dev/image/upload/s--O0TOmw4y--/f_auto/v1715772965/public/noProfile"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":17}},{"@type":"Comment","text":"When I read the title, I was terrified, and I was like: “This guy is cooked”, but tis kinda fun isn’t it? Like, in future, whenever you will remember your best memories, you’d remember: “Once, I corrupted 2 million db records, lol”","datePublished":"2026-01-14T15:36:32.550Z","url":"https://daily.dev/posts/UKwJQCYbS#c-TWVxSPa4e","author":{"@type":"Person","name":"Hassan Irfan","url":"https://daily.dev/hassanirfan527","image":"https://lh3.googleusercontent.com/a/ACg8ocIOedGZH8Zwh0lqhFG6aIaL7bx37YWe6J8ykX7W-OFfrIXfE94=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":16}},{"@type":"Comment","text":"I work a lot with SQL server and do a lot of backend work. I made quite a few mistakes, and broke a couple of DB’s myself, before I got to workable process to eliminate most of the errors I made.\n\nAlways test on a QA enviroment first.\nRead your sql scripts 7 times. It takes longer to fix an error than to read that script 7 times.\nAlways have a rollback script for the work to be done. If there is an error you can easily revert and fix.\nIf you are tired of testing, you know you are ready to push to production.\nEven if you do all these things above you will still make mistakes as there is a built in complexity in modern production db’s and servers, like you mentioned above.\nDocument your work and change process, if there is an investigation afterward chances are you will get off more easily as people can see you put in the precautionary work.","datePublished":"2026-01-15T08:01:10.787Z","url":"https://daily.dev/posts/UKwJQCYbS#c-HY0HT6cln","author":{"@type":"Person","name":"Graham Payne","url":"https://daily.dev/grahampayne","image":"https://lh3.googleusercontent.com/a/ACg8ocI7p1GB2Y_RYKvlZ6yuH4oF0tua8zIGmtK6q6kxnk8CutrJTA=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":14}},{"@type":"Comment","text":"The road to senior developer is littered with mistakes you made on the way. The mistakes teach you a lot more than the successes.","datePublished":"2026-03-09T18:32:39.307Z","url":"https://daily.dev/posts/UKwJQCYbS#c-7ieC50KQW","author":{"@type":"Person","name":"Stuart Greig","url":"https://daily.dev/stuartgreig","image":"https://media.daily.dev/image/upload/s--FoVqUWgr--/f_auto/v1772633885/avatars/avatar_V6TOuZS8XXplYvc5hNLgE?_a=BAMAMiiu0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}}]}
```

