Registry / database / migrate-mongodb

migrate-mongodb

JSON →
library4.0.0jsnpmunverified

Abstract migration framework for Node.js with optional MongoDB state storage. Version 4.0.0 provides a CLI and programmatic API for managing database migrations. The framework supports both file-based state storage and MongoDB-based state via the MONGO_CONNECTION_STRING environment variable, allowing seamless migration from the original tj/node-migrate package. It enables creating, up, and down migration commands with custom date formats and template files.

npm install migrate-mongodb
INSTALL
IMPORT
SIG · MIGRATE-MONGODB
M
migrate-mongodb
databasejavascriptv4.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

migrate
const migrate = require('migrate');
import migrate from 'migrate';
This package does not support ESM; use CommonJS require().
load
const set = migrate.load('path/to/state', 'path/to/migrations');
migrate.load({stateFile: '...', migrationsDirectory: '...'});
The load function expects two string arguments: state file path and migrations directory path. Do not pass an object.
set.up
set.up(function(err) { if (err) throw err; });
set.up().then(() => {});
The API uses callbacks, not promises. Wrap with util.promisify if needed.

Quickstart: install migrate, create a migration, run it up.

npm install migrate mkdir migrations # create a migration node_modules/.bin/migrate create initial-setup # migrations/1690000000000-initial-setup.js created, edit it: // exports.up = function(next){ // console.log('Running up'); // next(); // }; // exports.down = function(next){ // console.log('Running down'); // next(); // }; node_modules/.bin/migrate up
Debug
Known issues
breakingVersion 4.0.0 changed default CLI behavior. `migrate` now runs `up` by default instead of requiring a command. The `--state-file` option path is relative to current working directory.
fix
Use `migrate up` explicitly if needed, or update scripts relying on older CLI syntax.
affects: >=4.0.0
gotchaMongoDB state storage requires setting the MONGO_CONNECTION_STRING environment variable; the option is called --state-mongo, not --mongo-url.
fix
Use `--state-mongo MONGO_CONNECTION_STRING` or set env var directly.
affects: >=0.0.0
deprecatedCallback-based API is not deprecated but lacks Promise support; no plans to add Promises.
fix
Wrap with util.promisify or use a wrapper library.
affects: >=0.0.0
gotchaMigration filenames must be sortable alphabetically; use timestamps. If two migrations have the same timestamp, behavior is undefined.
fix
Use the default timestamp format (milliseconds) or a date format that ensures unique ordering.
affects: >=0.0.0
breakingVersion 3.x changed the state file format from JSON to a custom binary format. State files from 2.x are not compatible.
fix
Delete the old .migrate file and re-run all migrations.
affects: >=3.0.0 <4.0.0
Errors
Common errors & fixes
Error: Cannot find module 'migrate'
Package not installed or incorrect import path.
fix
Run `npm install migrate` and use `require('migrate')`.
migrate: command not found
migrate binary not in PATH.
fix
Use `npx migrate` or `./node_modules/.bin/migrate`.
TypeError: migrate.load is not a function
Incorrect usage of the migrate object.
fix
Use `const migrate = require('migrate');` then `set = migrate.load('state', 'dir');`.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
migrate-mongodb — npm install migrate-mongodb · libregistry