Easy Migration is a MongoDB plugin for writing and managing migrations. It gives you a clear, structured workflow for database changes — pass a URI, your collections, and a callback that runs per record.
Published on npm as mongodbplugin.
TL;DR#
What this is: A Node.js library that iterates over a primary MongoDB collection and runs your migration logic on each document, with access to related collections and a built-in logging helper.
What this isn’t: A full migration framework with versioning or rollback (rollback support is planned).
Install: npm i mongodbplugin
Features#
- Intuitive API — simple, documented methods for defining migrations
- Customizable logic — bring your own per-record callback to fit application needs
- Error handling — structured error reporting and logging for debugging
- Built-in logging —
writeLogpersists migration output to amigrationLogsfolder - Rollback support — planned
Quick Start#
npm i mongodbpluginUsage#
You need four things:
- Your MongoDB URI
- A primary collection to read migration data from
- The collections involved in the migration (primary plus any secondary/related collections)
- A callback with the logic to apply per record
const processMigration = require("mongodbplugin");
const mongoDB_URI = process.env.DB_URL;
const primaryCollection = require("./models/primaryCollection");
const secondaryCollection = require("./models/secondaryCollection");
const ternaryCollection = require("./models/ternaryCollection");
const callbackFn = require("./migrations/updateNewFieldsInDB");
// callbackFn runs once per record inside a loop
processMigration(
{
uri: mongoDB_URI,
options: {
// additional MongoDB connection options
},
},
primaryCollection,
[primaryCollection, secondaryCollection, ternaryCollection],
callbackFn
);Your callback receives the current document, the collections you passed in, and a writeLog helper:
// (data, primaryCollection, secondaryCollection, ternaryCollection, writeLog)
function migrate(data, primary, secondary, ternary, writeLog) {
writeLog("update", `Migrating document ${data._id}`);
// your migration logic here
}Call writeLog(action, logContent) anywhere inside the callback. Logs are saved under migrationLogs/.
Coming Soon#
- Improved overall performance
- Improved logging capabilities
- Rollback support