<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Santosh Gupta</title>
    <description>The latest articles on DEV Community by Santosh Gupta (@santosh327).</description>
    <link>https://dev.to/santosh327</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1355884%2Ffc665efc-121c-4e94-922b-b82c8c63d7c2.jpg</url>
      <title>DEV Community: Santosh Gupta</title>
      <link>https://dev.to/santosh327</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/santosh327"/>
    <language>en</language>
    <item>
      <title>I Built a MongoDB Migration Tool After One Bad Deploy</title>
      <dc:creator>Santosh Gupta</dc:creator>
      <pubDate>Sat, 06 Jun 2026 07:15:09 +0000</pubDate>
      <link>https://dev.to/santosh327/i-built-a-mongodb-migration-tool-after-one-bad-deploy-18j6</link>
      <guid>https://dev.to/santosh327/i-built-a-mongodb-migration-tool-after-one-bad-deploy-18j6</guid>
      <description>&lt;p&gt;A few months ago I shipped a bad MongoDB migration.&lt;/p&gt;

&lt;p&gt;Classic mistake.&lt;/p&gt;

&lt;p&gt;I had run 3 migrations.&lt;/p&gt;

&lt;p&gt;The third one had a bug.&lt;/p&gt;

&lt;p&gt;I only wanted to rollback &lt;strong&gt;that migration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Turns out with &lt;code&gt;migrate-mongo&lt;/code&gt;, rollback is mostly:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;undo the last applied migration&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Which sounds fine until you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multiple deployments&lt;/li&gt;
&lt;li&gt;multiple environments&lt;/li&gt;
&lt;li&gt;teammates deploying too&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;“Last applied” stops feeling obvious.&lt;/p&gt;

&lt;p&gt;I ended up manually undoing DB changes and fixing migration history myself.&lt;/p&gt;

&lt;p&gt;Not fun.&lt;/p&gt;

&lt;p&gt;That was the moment I realized our migration setup had started breaking down as the project grew.&lt;/p&gt;

&lt;h2&gt;
  
  
  The stuff I kept wishing existed
&lt;/h2&gt;

&lt;p&gt;After that incident I wrote down all the things I wanted from a migration tool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;run &lt;strong&gt;one migration file&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;rollback &lt;strong&gt;a specific migration&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;preview migrations before running (&lt;code&gt;dry-run&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;avoid concurrent deploys stepping on each other (locking)&lt;/li&gt;
&lt;li&gt;detect edited migrations (checksums)&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;redo&lt;/code&gt; command for local development&lt;/li&gt;
&lt;li&gt;TypeScript support without setup pain&lt;/li&gt;
&lt;li&gt;migration history that doesn’t disappear after rollback&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these felt unusual.&lt;/p&gt;

&lt;p&gt;They felt like things you eventually want once your project stops being small.&lt;/p&gt;

&lt;p&gt;So I ended up building one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Meet &lt;code&gt;mongo-migrate-kit&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;CLI name: &lt;code&gt;mmk&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A few examples:&lt;/p&gt;

&lt;p&gt;Run pending migrations:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mmk up&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Rollback a specific migration:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mmk down migration-name&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Preview before touching production:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mmk up --dry-run&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Redo during development:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mmk redo&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The hard problem: switching tools safely
&lt;/h2&gt;

&lt;p&gt;This was the part I cared about most.&lt;/p&gt;

&lt;p&gt;Migration tools are easy to adopt on day 1.&lt;/p&gt;

&lt;p&gt;They’re painful to switch after 50+ migrations already exist.&lt;/p&gt;

&lt;p&gt;I didn’t want people to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;rerun old migrations&lt;/li&gt;
&lt;li&gt;recreate indexes&lt;/li&gt;
&lt;li&gt;duplicate seed data&lt;/li&gt;
&lt;li&gt;accidentally touch production data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I added:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mmk import&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;It reads your existing &lt;code&gt;migrate-mongo&lt;/code&gt; changelog and adopts the migration history.&lt;/p&gt;

&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mmk up&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;only runs new migrations.&lt;/p&gt;

&lt;p&gt;No replaying old history.&lt;/p&gt;

&lt;p&gt;No scary production moments.&lt;/p&gt;

&lt;h2&gt;
  
  
  One thing I intentionally don't support
&lt;/h2&gt;

&lt;p&gt;Imported &lt;code&gt;migrate-mongo&lt;/code&gt; migrations are forward-only.&lt;/p&gt;

&lt;p&gt;You can’t rollback imported migrations using &lt;code&gt;mmk&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I could have tried to force compatibility, but I didn’t trust it enough to be safe.&lt;/p&gt;

&lt;p&gt;Different execution models + database tooling = not something I wanted to gamble with.&lt;/p&gt;

&lt;p&gt;So the tool fails loudly instead of pretending everything is reversible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Curious what other teams are doing
&lt;/h2&gt;

&lt;p&gt;If you're running MongoDB migrations in production:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What’s your current setup?&lt;/li&gt;
&lt;li&gt;Have you hit similar pain points?&lt;/li&gt;
&lt;li&gt;Are you still happy with &lt;code&gt;migrate-mongo&lt;/code&gt;?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Would genuinely love feedback.&lt;/p&gt;

&lt;p&gt;Project:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mongo-migrate-kit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Docs/demo:&lt;br&gt;
&lt;a href="https://mongo-migrate-kit.vercel.app" rel="noopener noreferrer"&gt;mongo-migrate-kit.vercel.app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;npm:&lt;br&gt;
&lt;a href="https://www.npmjs.com/package/mongo-migrate-kit" rel="noopener noreferrer"&gt;mongo-migrate-kit&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>node</category>
      <category>backend</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
