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)
--env-file <path>.env file to load (default: ./.env)
--no-envDo not load a .env file at all
--verboseShow debug output, including the underlying cause of an error (disables the spinner — debug lines and an animated frame would fight for the same terminal line)
--quietSuppress everything but errors
--no-colorDisable colored output — wins over every color environment variable
--jsonMachine-readable JSON output (every command except init — see init --format)
-V, --versionPrint the installed version
-h, --helpPrint help for the program or a command

Color detection

Without the flag, color is decided by MIGRONAUT_FORCE_COLOR > MIGRONAUT_NO_COLOR > FORCE_COLOR > NO_COLOR > TERM=dumb > whether the stream is an interactive TTY. A *FORCE_COLOR that is set and non-empty decides (0 forces color off, anything else forces it on); a *NO_COLOR that is set and non-empty forces it off.

The MIGRONAUT_-prefixed pair lets you pin migronaut's output without disturbing every other tool in the same shell. --no-color is an explicit instruction for this invocation, so it overrides all of them — including a FORCE_COLOR exported by your CI runner.

Short flags

Combined short flags are not supported: write -f -y, not -fy.

Running migrations

CommandDescription
migronaut upRun all pending migrations
migronaut up <file>Run a single migration
migronaut up --to <file>Apply pending migrations up to and including that file
migronaut down --to <file>Revert everything applied after that file (it stays applied)
migronaut up --stepApply each file as its own batch
migronaut up <file> --force --yesRe-run an already-applied file (short: -f -y)
migronaut up --strictAbort on a checksum mismatch
migronaut up --no-lockSkip the lock (dev only)
migronaut downRoll back the last batch
migronaut down <file>Roll back a single migration
migronaut down --batch <n>Roll back a specific batch
migronaut down --steps <n>Roll back the last N migrations
migronaut down --no-lockSkip the lock (dev only)
migronaut redoDown + up the last applied migration
migronaut redo <file>Down + up a specific migration
migronaut redo --no-lockSkip the lock (dev only)

Inspecting

CommandDescription
migronaut statusFull status table
migronaut status --checkExit 2 if any migration is pending (CI gate)
migronaut status --pending / --limit <n>Filter to pending rows / show only the last N (--limit is not combinable with --check)
migronaut list --pendingOnly pending migrations
migronaut list --appliedOnly applied migrations
migronaut dry-run upPreview what would apply
migronaut dry-run downPreview what would revert
migronaut dry-run down --steps <n>Preview reverting the last N
migronaut dry-run down --batch <n>Preview reverting a specific batch
migronaut dry-run up --to <file>Preview a staged rollout up to that file
migronaut dry-run down --to <file>Preview reverting everything applied after that file

Authoring

CommandDescription
migronaut create <name>Create a migration (default .js)
migronaut create <name> --tsCreate a .ts migration
migronaut create <name> --jsCreate a .js migration
migronaut create <name> --template <path>Use a custom template
migronaut initGenerate migronaut.config.js
migronaut init --format <js|ts|json>Config file format (--ts/--js are shorthands)
migronaut init --secret-providerGenerate a secret-manager config
migronaut init --forceOverwrite an existing config

Operations

CommandDescription
migronaut importAdopt a migrate-mongo changelog
migronaut import --from <c> / --to <c>Source / target collection
migronaut import --dry-runPreview the mapping
migronaut import --trust-hashReuse migrate-mongo's fileHash
migronaut import --forceImport into a non-empty changelog
migronaut lockShow who holds the migration lock
migronaut lock --jsonMachine-readable { held, holder }
migronaut auditCheck config, connectivity, transactions, indexes, lock, checksums
migronaut audit --jsonMachine-readable report; exit 22 when a check fails
migronaut unlockForce-release a stuck lock
migronaut unlock --yesRelease without confirmation (short: -y)

Exit codes

The code identifies why a run failed, so CI can branch on it. Success is always 0, and anything unmapped is 1 — a script testing != 0 keeps working unchanged. The full map is also exported from the package root as EXIT_CODES, so a wrapper script can mirror it without hardcoding numbers.

CodeMeaning
0Success (or nothing to do)
1An unclassified error
2PENDING_MIGRATIONSstatus --check found pending migrations
3LOCK_ALREADY_HELD — another run holds the lock
4CHECKSUM_MISMATCH — an applied file was edited (with --strict)
5CONNECTION_FAILED — could not reach MongoDB
6CONFIG_INVALID — bad configuration or flags
7MIGRATION_EXECUTION_FAILED — a migration threw
8MIGRATION_FILE_NOT_FOUND
9NOT_APPLIED — nothing to revert under that name
10LOCK_LOST — the lock was lost mid-run
11RUN_ABORTED — stopped by SIGINT/SIGTERM
12HOOK_FAILED — a lifecycle hook threw
13MIGRATION_IRREVERSIBLE — an imported migrate-mongo record
14MIGRATION_TIMEOUT — a migration exceeded timeoutMs
15TRANSACTIONS_UNSUPPORTED — transactions need a replica set / mongos
16CONFIG_FILE_EXISTSinit found an existing config (idempotent no-op)
17IMPORT_TARGET_NOT_EMPTYimport found records (re-run with --force)
18MIGRATION_FILE_EXISTScreate name collision
19MIGRATION_INVALID_NAME — a rejected (e.g. path-traversing) name
20MIGRATION_INVALID_EXPORT — a migration file without valid up/down
21LOCK_RELEASE_FAILED — the lock could not be released
22AUDIT_FAILED — an audit check failed (warnings stay 0)
130 / 143Killed by a second SIGINT / SIGTERM

Released under the MIT License.