mysql-mongodb-migrate
v0.9.2
Published
migrate mysql tables to mongodb collections
Downloads
6
Maintainers
Readme
MySQL MongoDB Migrate
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