mysql-mongodb-migrate

0.9.2 • Public • Published

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

Dependents (0)

Package Sidebar

Install

npm i mysql-mongodb-migrate

Weekly Downloads

1

Version

0.9.2

License

MIT

Unpacked Size

12.3 kB

Total Files

10

Last publish

Collaborators

  • asankanissanka