Registry / database / migrate-mongoose-custom

migrate-mongoose-custom

JSON →
library0.2.2jsnpmunverified

A node-based migration framework for Mongoose, forked from migrate-mongoose with updated mongoose version (4 to 5) and removal of throw error when no migrations to run. Current version 0.2.2. Stores migration state in MongoDB, supports custom config files, environment variables, and CLI commands (create, up, down, list, prune). Differentiators: global migration state (no local file state), access to mongoose models, promise/callback support, and ability to delete unused migrations. Ideal for projects already using mongoose and deploying on platforms like Heroku.

npm install migrate-mongoose-custom
INSTALL
IMPORT
SIG · MIGRATE-MONGOOSE-C
M
migrate-mongoose-custom
databasejavascriptv0.2.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.

migrate-mongoose-custom
const migrate = require('migrate-mongoose-custom');
import migrate from 'migrate-mongoose-custom';
Package does not support ESM imports; use CommonJS require.

Shows how to install, define a migration with up/down functions using async/await, and run it via CLI.

// Install: npm install migrate-mongoose-custom // Create a migration file (e.g., ./migrations/001-add-users.js): module.exports.up = async function(next) { const User = this.model('User', new this.Schema({ name: String, email: { type: String, unique: true } })); await User.create({ name: 'Alice', email: 'alice@example.com' }); next(); }; module.exports.down = async function(next) { const User = this.model('User'); await User.deleteMany({}); next(); }; // Run from command line: // ./node_modules/.bin/migrate up -d mongodb://localhost/mydb
Debug
Known issues
gotchaRequires mongoose version 5 (compatible with 5.x only).
fix
Ensure mongoose@5 is installed.
affects: >=0.0.0
gotchaDoes not support ESM imports; CommonJS only.
fix
Use require() instead of import.
affects: >=0.0.0
gotchaGlobal migration state; no local file tracking. This may surprise users expecting file-based state.
fix
Understand that migration state is stored in MongoDB collection.
affects: >=0.0.0
deprecatedThis is a fork of migrate-mongoose with limited maintenance. May lag behind upstream changes.
fix
Consider using the original migrate-mongoose or migrate-mongoose-custom (check latest version).
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'migrate-mongoose-custom'
Package name typo or not installed.
fix
npm install migrate-mongoose-custom
TypeError: this.model is not a function
Mongoose model access syntax incorrect in migration.
fix
Use this.model('ModelName', schema) inside up/down functions.
Error: dbConnectionUri is required
Missing -d or MIGRATE_dbConnectionUri environment variable.
fix
Provide connection URI via -d or set MIGRATE_dbConnectionUri env var.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies
mongooserequiredrequired for database connection and schema operations
Agent activity
6 hits · last 30 days
node
6
Resources
migrate-mongoose-custom — npm install migrate-mongoose-custom · libregistry