Registry / database / mongo-migrate

mongo-migrate

JSON →
library2.0.2jsnpmunverified

A MongoDB migration framework for Node.js. Version 2.0.2 (latest) is stable but in legacy maintenance mode — the package has not been updated since 2015 and the GitHub repository is archived. It provides a simple up/down migration pattern inspired by visionmedia/node-migrate, storing migration state in a MongoDB collection. Alternatives like migrate-mongo offer modern ESM support, async/await, and active maintenance. Key differentiator: direct MongoDB driver integration via db object in migration functions.

npm install mongo-migrate
INSTALL
IMPORT
SIG · MONGO-MIGRATE
M
mongo-migrate
databasejavascriptv2.0.2
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.

exports.up
exports.up = function(db, next) { /* ... */ };
exports.up = async function(db) { /* ... */ };
The migration functions use callbacks (next), not promises or async/await.
exports.down
exports.down = function(db, next) { /* ... */ };
exports.down = (db) => { return Promise.resolve(); };
Must call next() to complete the migration, not return a promise.
mongo-migrate (CLI)
node ./node_modules/mongodb-migrate -runmm up
mongodb-migrate up
The CLI is not installed globally; run via relative path or use npx.

Creates a migration file with up and down functions, then runs migrations via CLI.

// Install // npm install mongodb-migrate // Create a migration file: ./migrations/001-add-users.js exports.up = function (db, next) { db.collection('users').insertMany([ { name: 'Alice', role: 'admin' }, { name: 'Bob', role: 'user' } ], next); }; exports.down = function (db, next) { db.collection('users').deleteMany({ name: { $in: ['Alice', 'Bob'] } }, next); }; // Run migrations from terminal: // node ./node_modules/mongodb-migrate -runmm up
Debug
Known issues
breakingThe package is unmaintained; GitHub archived. Use alternative like migrate-mongo.
fix
Switch to migrate-mongo: npm install migrate-mongo
affects: >=0.0.0
breakingMongoDB driver version compatibility: uses old driver (<3.0) - may not work with modern MongoDB versions.
fix
Use an older MongoDB server or migrate to a maintained library.
affects: >=2.0.0
deprecatedPassing a JSON string via -dbc is error-prone; prefer -cfg with a file.
fix
Use -cfg config.json or set environment variables.
affects: >=0.0.0
gotchaError handling: if next(err) is called, the migration attempts to revert the opposite direction, which may cause data loss.
fix
Ensure proper error handling; test migrations in a staging environment.
affects: >=0.0.0
gotchaThe CLI must be invoked with -runmm flag; otherwise it does nothing.
fix
Always include -runmm in command: node ./node_modules/mongodb-migrate -runmm up
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module './node_modules/mongodb-migrate'
CLI invoked without correct relative path.
fix
Run from project root: node ./node_modules/mongodb-migrate -runmm up
TypeError: db.collection is not a function
Using db.Collection (capital C) with older MongoDB driver.
fix
Use db.collection('name') (lowercase) for MongoDB 2.x+.
Error: connect ECONNREFUSED
MongoDB not running or connection string wrong.
fix
Start mongod or check host/port in config or -dbc JSON.
mongodb-migrate: command not found
Not installed globally.
fix
Use npx: npx mongodb-migrate -runmm up, or run via relative path.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
mongodbrequiredRequired for database operations; the migration framework uses the MongoDB driver internally.
Agent activity
7 hits · last 30 days
node
6
Resources
mongo-migrate — npm install mongo-migrate · libregistry