Registry / database / mangoose-migrate

mangoose-migrate

JSON →
library0.1.7jsnpmunverified

A lightweight migration tool for Mongoose (MongoDB), inspired by Django's migration system. Version 0.1.7 is the latest stable release, with no frequent updates. It provides a CLI for creating and running migrations, supports configuration via environment variables, config file, or CLI arguments. Key differentiators: minimal API focused on simple schema migrations (CreateModel, AddField), designed for small to medium projects, but limited features compared to alternatives like migrate-mongoose.

npm install mangoose-migrate
INSTALL
IMPORT
SIG · MANGOOSE-MIGRATE
M
mangoose-migrate
databasejavascriptv0.1.7
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.

Migration
import { Migration } from 'mangoose-migrate/core'
import { Migration } from 'mangoose-migrate'
Migration class is exported from the 'core' subpath, not the main package.
CreateModel
import { CreateModel } from 'mangoose-migrate/operations'
import CreateModel from 'mangoose-migrate'
Operations like CreateModel are in the 'operations' subpath.
default export
export default class InitialMigration extends Migration { ... }
module.exports = class InitialMigration ...
Migrations use ES module syntax; does not export from mangoose-migrate directly.

Shows installation, configuration via env var, migration creation, and a complete migration file with CreateModel operation.

// Step 1: Install // npm i -g mangoose-migrate // Step 2: Set environment variable process.env.MONGODB_URI = 'mongodb://localhost:27017/mydb' ?? ''; // Step 3: Create a migration file // Run: npx mangoose-migrate make add_users // Step 4: Edit the generated file in ./migrations/ import { Migration } from 'mangoose-migrate/core'; import { CreateModel } from 'mangoose-migrate/operations'; export default class AddUsers extends Migration { constructor() { super('add_users'); } async up(db) { this.addOperation( new CreateModel('User', { name: { type: String, required: true }, email: { type: String, unique: true }, age: Number, createdAt: { type: Date, default: Date.now }, }) ); } async down(db) { // Revert operations can be implemented here } } // Step 5: Run migrations // npx mangoose-migrate migrate
Debug
Known issues
gotchaThe package name has a typo 'mangoose' instead of 'mongoose'. This may cause confusion with the actual Mongoose package.
fix
Be careful when copy-pasting package names; use 'mangoose-migrate' as spelled.
affects: >=0.0.0
gotchaMigration files must have a default export of a class extending Migration. Using named exports or other patterns will not be recognized.
fix
Use `export default class YourMigration extends Migration { ... }`
affects: >=0.0.0
gotchaThe `connectionUri` in config must include the database name. Omitting it may lead to 'Database not specified' errors.
fix
Ensure the URI ends with '/databaseName' (e.g., mongodb://localhost:27017/mydb).
affects: >=0.0.0
gotchaOperations like CreateModel only accept Mongoose schema definitions, not full Mongoose Schema objects.
fix
Pass plain object definitions, not Schema instances.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'mangoose-migrate/core'
Import path is incorrect; the package may not be installed or subpath exports not supported.
fix
Ensure mangoose-migrate is installed locally (npm install mangoose-migrate) and your Node.js version supports subpath exports (>=12.17.0).
Migration 'add_users' is not a constructor
The migration file does not export a default class extending Migration.
fix
Add `export default class AddUsers extends Migration { ... }` and import Migration from 'mangoose-migrate/core'.
Cannot read properties of undefined (reading 'addOperation')
The `up` method inside the migration class is not using `this.addOperation` correctly, or the context is lost (arrow function).
fix
Use a regular async function for `up` (not arrow function) and call `this.addOperation(...)`.
MongoDB connection error: Authentication failed
The connection URI contains invalid credentials or missing authSource.
fix
Verify the MONGODB_URI includes correct username/password and optionally add `?authSource=admin`.
Upgrade
Version history
0.1.7latest on npm
Audit
Dependencies
mongooserequiredPeer dependency for defining schemas and interacting with MongoDB
Agent activity
9 hits · last 30 days
node
8
Resources
mangoose-migrate — npm install mangoose-migrate · libregistry