Skip to content

shoutout-labs/mysql-mongodb-migrate

Repository files navigation

MySQL MongoDB Migrate

npm version Build Status

Data migration module for migrating mysql tables to mongodb db collections

Installing

npm install mysql-mongodb-migrate --save

Quick Usage

const MigrationJob = require('mysql-mongodb-migrate');

let sourceConnectionOptions = {
    host: <MYSQL_HOST>,
    port: <MYSQL_PORT>,
    user: <MYSQL_USER>,
    password: <MYSQL_PASSWORD>,
    ssl: <MYSQL_SSL> //optional (Ex:- 'Amazon RDS')
};
let targetConnectionOptions = {
    host: <MONGODB_ENDPOINT>,
    user: <MONGODB_USERNAME>,
    password: <MONGODB_PASSWORD>
};

const migrationJob = new MigrationJob(<MYSQL_DATABASE_NAME>, <MYSQL_TABLE_NAME>, <MONGODB_DATABASE_NAME>, <MONGODB_COLLECTION_NAME>, sourceConnectionOptions, targetConnectionOptions, <MYSQL_READ_LIMIT_PER_ITERATION>, <MYSQL_READ_THROUGHPUT>);


migrationJob.run()

Adavance Usage

Initialize

const MigrationJob = require('mysql-mongodb-migrate');

let sourceConnectionOptions = {
    host: <MYSQL_HOST>,
    port: <MYSQL_PORT>,
    user: <MYSQL_USER>,
    password: <MYSQL_PASSWORD>,
    ssl: <MYSQL_SSL> //optional (Ex:- 'Amazon RDS')
};
let targetConnectionOptions = {
    host: <MONGODB_ENDPOINT>,
    user: <MONGODB_USERNAME>,
    password: <MONGODB_PASSWORD>
};

const migrationJob = new MigrationJob(<MYSQL_DATABASE_NAME>, <MYSQL_TABLE_NAME>, <MONGODB_DATABASE_NAME>, <MONGODB_COLLECTION_NAME>, sourceConnectionOptions, targetConnectionOptions, <MYSQL_READ_LIMIT_PER_ITERATION>, <MYSQL_READ_THROUGHPUT>);

Set dynamodb filter expression - filter when scanning dynamodb

const filterExpression = 'attr1 = val1';

migrationJob.setSourcefilterExpression(filterExpression);

Set data filter function - filter after scan result - similar to lodash filter

const filterFunction = (item) =>{
    return item.attr1 !== null;
}

migrationJob.setFilterFunction(metadata.filterFunction);

Set data mapper function - similar to lodash map

const mapperFunction = (item) =>{
    return {
        mappedAttr1 : item.attr1,
        mappedAttr2 : item.attr2
    }
}

migrationJob.setMapperFunction(mapperFunction);

Run

migrationJob.run()

Testing

npm test

About

Migrate data from MySQL tables to MongoDB collections

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published