Skip to content

CLI Cheatsheet

Every command and flag on one page. For details, follow the link on each command.

Global flags

Available on every command, highest precedence:

FlagDescription
--uri <uri>MongoDB connection URI
--db <name>Database name
--dir <path>Migrations directory
--config <path>Path to a config file (overrides auto-discovery)
--jsonMachine-readable JSON output (on data commands)

Running migrations

CommandDescription
mmk upRun all pending migrations
mmk up <file>Run a single migration
mmk up --stepApply each file as its own batch
mmk up <file> --force --yesRe-run an already-applied file
mmk up --strictAbort on a checksum mismatch
mmk up --no-lockSkip the lock (dev only)
mmk downRoll back the last batch
mmk down <file>Roll back a single migration
mmk down --batch <n>Roll back a specific batch
mmk down --steps <n>Roll back the last N migrations
mmk redoDown + up the last applied migration
mmk redo <file>Down + up a specific migration

Inspecting

CommandDescription
mmk statusFull status table
mmk status --checkExit 1 if any migration is pending (CI gate)
mmk list --pendingOnly pending migrations
mmk list --appliedOnly applied migrations
mmk dry-run upPreview what would apply
mmk dry-run downPreview what would revert
mmk dry-run down --steps <n>Preview reverting the last N

Authoring

CommandDescription
mmk create <name>Create a migration (default .js)
mmk create <name> --tsCreate a .ts migration
mmk create <name> --jsCreate a .js migration
mmk create <name> --template <path>Use a custom template
mmk initGenerate mmk.config.js
mmk init --ts / --jsonGenerate .ts / .json config
mmk init --secret-providerGenerate a secret-manager config
mmk init --forceOverwrite an existing config

Operations

CommandDescription
mmk importAdopt a migrate-mongo changelog
mmk import --from <c> / --to <c>Source / target collection
mmk import --dry-runPreview the mapping
mmk import --trust-hashReuse migrate-mongo's fileHash
mmk import --forceImport into a non-empty changelog
mmk unlockForce-release a stuck lock
mmk unlock --yesRelease without confirmation

Exit codes

CodeMeaning
0Success (or nothing to do)
1An error occurred, or --check found pending migrations

Released under the MIT License.