Registry / database / mongoose-migration

mongoose-migration

JSON →
library0.2.0jsnpmunverified

Data migration tool for Mongoose (v0.2.0). This package allows you to manage database migrations for Mongoose models via a CLI tool. It uses a configuration file (`.migrate.json`) to define the database connection and model paths, and provides commands to create, run, and rollback migrations. The last release was in 2014, and the project has no recent updates. It is a lightweight alternative to more robust migration tools like `migrate-mongoose`, but lacks features like environments and timestamp-based migration. Note that the package is outdated and may not be compatible with modern Mongoose versions (>=5.x).

npm install mongoose-migration
INSTALL
IMPORT
SIG · MONGOOSE-MIGRATION
M
mongoose-migration
databasejavascriptv0.2.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 CLI
npm install mongoose-migration --save-dev
import migrate from 'mongoose-migration'
No JavaScript import; the tool is used via CLI commands like `migrate init`, `migrate create`, `migrate up`.
Migration script exports
exports.up = function(next) { ... }; exports.down = function(next) { ... };
export function up(next) { ... }
Use CommonJS exports, not ES modules. The migration functions receive a `next` callback.

Shows how to create and run a migration using the CLI and CommonJS module exports.

// Initialize configuration // npx migrate init // Edit .migrate.json with mongoose models path // Create a migration // npx migrate create "Add field" // Edit the generated file in migrations/ folder: exports.up = function(next) { this.model('User').updateMany({}, { $set: { newField: 'value' } }, { strict: false }, function(err, res) { if (err) console.error(err); next(); }); }; exports.down = function(next) { this.model('User').updateMany({}, { $unset: { newField: 1 } }, { strict: false }, function(err, res) { if (err) console.error(err); next(); }); }; // Run all migrations: // npx migrate
Debug
Known issues
deprecatedOutdated package: last release in 2014, no compatibility with Mongoose 5.x+.
fix
Use `migrate-mongoose` or other actively maintained migration tools.
affects: >=0.2.0
gotchaThe `this` context in migration functions refers to the migration context, not the module. Must call `this.model('Name')` to access Mongoose models.
fix
Ensure migration scripts use `this.model('ModelName')` instead of directly `require`ing models.
affects: all
gotchaConfiguration file `.migrate.json` must exist in project root; CLI commands may fail otherwise.
fix
Run `migrate init` first and ensure the file is correctly configured.
affects: all
Errors
Common errors & fixes
Error: Cannot find module './models/user.js'
Incorrect path in `.migrate.json` models configuration.
fix
Ensure the path is relative to the project root (e.g., 'models/user.js' or absolute path).
TypeError: this.model is not a function
Using arrow functions in migration exports which do not bind `this` to migration context.
fix
Use regular function expressions: `exports.up = function(next) { ... }`.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
mongooserequiredPeer dependency required for model access in migration scripts
Agent activity
8 hits · last 30 days
node
6
Resources
mongoose-migration — npm install mongoose-migration · libregistry