Data migration module for migrating mysql tables to mongodb db collections
npm install mysql-mongodb-migrate --save
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()
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>);
const filterExpression = 'attr1 = val1';
migrationJob.setSourcefilterExpression(filterExpression);
const filterFunction = (item) =>{
return item.attr1 !== null;
}
migrationJob.setFilterFunction(metadata.filterFunction);
const mapperFunction = (item) =>{
return {
mappedAttr1 : item.attr1,
mappedAttr2 : item.attr2
}
}
migrationJob.setMapperFunction(mapperFunction);
migrationJob.run()
npm test