Skip to content

ishanjain1502/easyMigration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mongo Easy Migration Plugin

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.

Features

  • 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.

Setup

install library from npm using

npm i mongodbplugin

Usage

What you need is your

  1. Your mongoDB URI
  2. Your primary collection on which migration has to take data from
  3. Your list of remaining collections, or the collection on which the migration is to be performed on
  4. 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
*/

Coming Soon

Improved overall Performance.
Improved logging capabilities.
Rollback support.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published