Skip to content

Error Codes

Every error thrown by mongo-migrate-kit extends MmkError and carries a typed code, a message, and an optional context object. Catch MmkError and switch on code for precise handling:

ts
import { MmkError } from 'mongo-migrate-kit';

try {
  await migrator.up();
} catch (err) {
  if (err instanceof MmkError) {
    console.error(err.code, '—', err.message, err.context);
  }
}

In --json mode, the CLI prints { "error": { "code", "message" } } and exits 1.

Reference

CodeError classWhen it's thrownWhat to do
LOCK_ALREADY_HELDLockAlreadyHeldErrorAnother run holds the lock within its TTLWait, or mmk unlock if it's stale
LOCK_RELEASE_FAILEDLockReleaseFailedErrorThe lock couldn't be releasedCheck DB connectivity; retry
CHECKSUM_MISMATCHChecksumMismatchErrorAn applied file was edited (in --strict)Don't edit applied files — write a new migration
MIGRATION_FILE_NOT_FOUNDMigrationFileNotFoundErrorA named migration file doesn't existCheck the filename and migrationsDir
MIGRATION_INVALID_NAMEMigrationInvalidNameErrorA migration name escapes the migrations dirUse a bare filename, not a path
MIGRATION_INVALID_EXPORTMigrationInvalidExportErrorA file is missing up/down functionsExport both up and down
MIGRATION_EXECUTION_FAILEDMigrationExecutionFailedErrorA migration's up/down threwRead the cause; fix the migration logic
CONFIG_INVALIDConfigInvalidErrorConfig failed validationCheck required fields and types
CONFIG_FILE_EXISTSConfigFileExistsErrormmk init found an existing configUse --force to overwrite
CONNECTION_FAILEDConnectionFailedErrorCouldn't connect to MongoDBVerify uri/dbName and that Mongo is up
ALREADY_APPLIEDAlreadyAppliedErrorA target migration is already appliedUse --force to re-run intentionally
NOT_APPLIEDNotAppliedErrorTried to revert a migration that isn't appliedRun mmk status to see what's applied
IMPORT_TARGET_NOT_EMPTYImportTargetNotEmptyErrormmk import target already has recordsUse --force to import anyway
MIGRATION_IRREVERSIBLEIrreversibleMigrationErrorTried to revert an imported migrate-mongo recordWrite a new forward migration instead

See Troubleshooting for step-by-step fixes for the most common ones.

Released under the MIT License.