Easy Migration is a MongoDB plugin designed to simplify the process of writing and managing migrations in MongoDB databases. It streamlines the development workflow by providing a clear and structured approach to database changes.
- Intuitive API: Write migrations with ease using simple and well-documented methods.
- Rollback Support: Provides an easy way to undo migrations (coming soon)
- Customizable: Supports custom migration logic to suit your application needs.
- Error Handling: Robust error reporting and logging to help debug issues.
install library from npm using
npm i mongodbplugin
What you need is your
- Your mongoDB URI
- Your primary collection on which migration has to take data from
- Your list of remaining collections, or the collection on which the migration is to be performed on
- Callback function with logic of what is required to be done
const processMigration = require("mongodbplugin");
let mongoDB_URI = process.env.DB_URL
let primaryCollection = require("./models/primaryCollection");
let secondaryCollection = require("./models/secondaryCollection");
let ternaryCollection = require("./models/ternaryCollection");
let callbackFn = require("./migrations/updateNewFieldsInDB);
// the callbackFn should consists of what logic you want to impliment on per record basis, as this will be called inside a loop.
processMigration( { uri:mongoDB_URI, options: {
// this includes further options that you want to pair up with mongodb
}},
primaryCollection,
[ primaryCollection, secondaryCollection, ternaryCollection ],
callbackFn( data, primaryCollection, secondaryCollection, ternaryCollection, writeLog ) // spread apart your collections here
// you can use writeLog function to write your logs on system which will get saved inside a folder migrationLogs
)
/**
writeLog(action, logContent);
you can directly call this function inside your callback
*/
Improved overall Performance.
Improved logging capabilities.
Rollback support.