explaingit

guptasantosh327/mongo-migrate-kit

15TypeScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A TypeScript CLI tool for managing MongoDB database migrations with precise controls: run or roll back single files, dry-run mode, atomic locking, checksum tamper detection, lifecycle hooks, and full audit trail. Drop-in upgrade from migrate-mongo.

Mindmap

mindmap
  root((mongo-migrate-kit))
    Running Migrations
      Run all pending
      Run single file
      Dry run preview
    Rolling Back
      By batch number
      By recent steps
      Single file rollback
    Safety Features
      Atomic lock
      SHA-256 checksums
      Audit trail
    Lifecycle Hooks
      Before and after all
      Before and after each
      On error
    Setup
      npm install
      mmk init config
      Env var support
    Migration from migrate-mongo
      mmk import command
      Changelog adopted
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Safely update your MongoDB database structure across multiple deployments without running every migration each time.

USE CASE 2

Roll back a broken migration in production by reverting just that one file, without touching unrelated changes.

USE CASE 3

Test what a migration will do before it runs, using dry-run mode so nothing in the database changes.

USE CASE 4

Migrate an existing migrate-mongo project to get better controls without rewriting any migration files.

Tech stack

TypeScriptNode.jsMongoDBnpm CLIESMCommonJS

Getting it running

Difficulty · easy Time to first run · 5min

Install via npm, run mmk init to generate a config file. Connection string and DB name can be passed as env vars instead. No extra build tools needed.

MIT license, free to use, modify, and distribute in personal or commercial projects. Just keep the copyright notice.

In plain English

mongo-migrate-kit is a command-line tool for managing MongoDB database migrations in Node.js projects. A migration is a script that changes the structure or content of a database in a controlled, versioned way: for example, adding an index, renaming a field, or moving data between collections. This tool is written in TypeScript and works in TypeScript, ESM, and CommonJS projects without requiring extra build-step tools. The main selling point over older tools like migrate-mongo is a more precise set of controls. You can run a single named migration file rather than being forced to run everything pending. You can roll back by batch number, by a count of recent steps, or by a single file. There is a dry-run mode that prints exactly what would happen without touching the database at all. An atomic lock stored in MongoDB itself prevents two deployment processes from running migrations at the same time. SHA-256 checksums are recorded when a migration is applied, so the tool can detect if the file was edited afterward, which is a common source of hard-to-debug inconsistencies. When you roll back, the history record is updated rather than deleted, so you always have a full audit trail. You can also define lifecycle hooks at four points in a migration run (before all, after all, before each, after each, and on error) and opt individual migrations into transactions so that a migration either fully completes or fully aborts. If you are already using migrate-mongo, a single mmk import command reads your existing changelog and adopts it as-is, so past migrations are recognized as already applied and only new ones will run. No data is lost and no migration files need to be rewritten. Install it from npm, run mmk init to generate a config file, then use mmk create, mmk up, mmk down, and mmk status to manage migrations. A config file is optional if you prefer to pass the database connection string and database name as environment variables. Full documentation is hosted separately. The project is licensed under MIT.

Copy-paste prompts

Prompt 1
I'm using mongo-migrate-kit. Show me how to create a migration that adds an index to a collection and can be safely rolled back.
Prompt 2
Using mongo-migrate-kit, how do I run only one specific migration file instead of all pending ones? Give me the exact CLI command.
Prompt 3
I'm migrating from migrate-mongo to mongo-migrate-kit. Walk me through the mmk import command and what to check afterward.
Prompt 4
Show me how to set up lifecycle hooks in mongo-migrate-kit so I can log a message before and after each migration runs.
Prompt 5
How do I configure mongo-migrate-kit using only environment variables, without a config file? List the variable names I need.
Open on GitHub → Explain another repo

← guptasantosh327 on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.