A minimalistic migration and seeding package for MongoDB that automates running migration files on app startup. Version 1.0.3 provides a simple synchronous initializer that scans a folder for files containing 'migration' in their name and executes them sequentially. It is designed for small projects or prototypes where a full migration framework is overkill. The package has no runtime dependencies beyond the native MongoDB driver. It does not support rollbacks, configuration files, or CLI commands; migrations are automatically run each time the application starts. The release cadence is unknown; the package has seen no recent updates. Compared to alternatives like migrate-mongo or mongodb-migrate, this package is much simpler but lacks features like down-migrations, version locking, and asynchronous control.
npm install migration-mongodbNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to initialize and run MongoDB migrations automatically using the default exported function.
Make migration functions idempotent by checking existence before creation, or use a migration tool with state tracking.
Rename files to include 'migration' in the filename, e.g., 'create-users-migration.js'.
Manually handle rollbacks in your application or choose a migration framework that supports down migrations.
Access the native db via mongoose.connection.db and pass it instead of relying on the package's connection logic, or use a different migration tool.
Use require('migration-mongodb') or configure your bundler/Node to handle CommonJS modules.Ensure the migration folder exists and contains at least one file with 'migration' in its filename.
Add a check: if (await db.listCollections({name: 'yourCollection'}).hasNext()) return;