Registry / database / migrate-mongo

migrate-mongo

JSON →
library14.0.7jsnpmunverified

A database migration tool for MongoDB in Node.js, currently at version 14.0.7. Supports MongoDB drivers 4.x through 7.x and requires Node.js >=20.0.0. It provides CLI commands (init, create, up, down, status) and programmatic API. Key differentiators: lightweight, lock-based concurrency, checksum validation, and support for both CommonJS and ESM module systems. Common pitfalls include incorrect configuration file exports, missing peer dependency mongodb, and improper use of up/down functions in migration files.

npm install migrate-mongo
INSTALL
IMPORT
SIG · MIGRATE-MONGO
M
migrate-mongo
databasejavascriptv14.0.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default
import migrateMongo from 'migrate-mongo'
import { migrateMongo } from 'migrate-mongo'
Default export; named exports also available for individual functions.
up
import { up } from 'migrate-mongo'
import up from 'migrate-mongo'
Named export for programmatic use, not default.
down
import { down } from 'migrate-mongo'
import down from 'migrate-mongo'
Named export for programmatic use, not default.
config
import { config } from 'migrate-mongo'
const config = require('migrate-mongo').config
Both CJS and ESM supported; ESM recommended for modern projects.

Shows full workflow: install, init, create migration file with up/down functions, run via CLI or programmatic API.

// 1. Install: npm install migrate-mongo mongodb // 2. Initialize project: npx migrate-mongo init // 3. Configure 'migrate-mongo-config.js' with your MongoDB URL and database name. // 4. Create a migration: npx migrate-mongo create add-users // 5. Edit the generated file in migrations/: export async function up(db, client) { await db.collection('users').insertOne({ name: 'John', email: 'john@example.com' }); } export async function down(db, client) { await db.collection('users').deleteOne({ name: 'John' }); } // 6. Run migrations: npx migrate-mongo up // Programmatic usage: import { up, down, config } from 'migrate-mongo'; const migrationConfig = await config.read(); await up(migrationConfig); // or await down(migrationConfig);
migrate-mongo --version
Debug
Known issues
breakingNode.js >=20.0.0 required as of v14. Older versions will fail.
fix
Upgrade Node.js to 20 or later.
affects: >=14.0.0
breakingMongoDB driver versions below 4.4 are not supported; driver 7.x requires specific connection options.
fix
Install mongodb driver ^4.4.1 || ^5.0.0 || ^6.0.0 || ^7.0.0.
affects: >=14.0.0
deprecateduseNewUrlParser and useUnifiedTopology options are deprecated in MongoDB driver 4.x+.
fix
Remove these options from config; they are now default.
affects: >=4.0.0
gotchaIf using ESM (moduleSystem: 'esm'), migration files must use .mjs extension or set "type": "module" in package.json.
fix
Use .mjs extension or configure package.json appropriately.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'migrate-mongo'
migrate-mongo not installed or not in PATH (global install missing).
fix
Install locally with 'npm install migrate-mongo --save-dev' or globally with 'npm install -g migrate-mongo'.
Error: Collection not found: changelog
Migration database not initialized; need to run 'migrate-mongo up' first.
fix
Run 'migrate-mongo up' to apply pending migrations and create changelog collection.
MongoParseError: options usecreateindex, usefindandmodify are not supported
Deprecated options passed to MongoDB driver.
fix
Remove 'useCreateIndex' and 'useFindAndModify' from config; they are no longer needed.
Upgrade
Version history
14.0.7latest on npm
Audit
Dependencies
mongodbrequiredPeer dependency for database connection. Must be installed separately.
Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
migrate-mongo — npm install migrate-mongo · libregistry