Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/MigrationJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MigrationJob {
this.mapperFunction = (item) => { return item; };
this.filterFunction = () => { return true; };
this.dynamoDBDAO = new DynamoDBDAO(sourceTableName,sourceConnectionOptions.region,sourceConnectionOptions.accessKeyId,sourceConnectionOptions.secretAccessKey);
this.mongoDBDAO = new MongoDBDAO(this.targetTableName, this.targetDbName,targetConnectionOptions.host, targetConnectionOptions.user, targetConnectionOptions.password);
this.mongoDBDAO = new MongoDBDAO(this.targetTableName, this.targetDbName, targetConnectionOptions.connectionString);
this.dynamodbEvalLimit = dynamodbEvalLimit || 100;
this.filterExpression = null;
this.expressionAttributeNames = null;
Expand Down Expand Up @@ -90,4 +90,4 @@ class MigrationJob {
}
}

module.exports = MigrationJob;
module.exports = MigrationJob;
11 changes: 5 additions & 6 deletions src/connectors/MongoDBConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ let client;

class MongoDBConnector {

static getConnection(database,host,user,password) {
static getConnection(databaseName, connectionString) {
return new Promise(async (resolve, reject) => {
try {
if (client) {
resolve(client.db(database));
resolve(client.db(databaseName));
} else {
let url = 'mongodb://' + user + ':' + password + '@' + host;
client = new MongoClient(url,{ useNewUrlParser: true });
client = new MongoClient(connectionString);
await client.connect();
resolve(client.db(database));
resolve(client.db(databaseName));
}
} catch (error) {
console.error(error);
Expand All @@ -29,4 +28,4 @@ class MongoDBConnector {
}
}

module.exports = MongoDBConnector;
module.exports = MongoDBConnector;
14 changes: 6 additions & 8 deletions src/dao/MongoDBDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ const lodash = require('lodash');
const MongoDBConnector = require('./../connectors/MongoDBConnector');

class MongoDBDAO {
constructor(tableName, databaseName,host,user,password) {
constructor(tableName, databaseName, connectionString) {
this.tableName = tableName;
this.databaseName = databaseName;
this.host = host;
this.user = user;
this.password = password;
}
this.databaseName = databaseName
this.connectionString = connectionString;
}

async intertOrUpdateItems(items) {
let dbConn = await MongoDBConnector.getConnection(this.databaseName,this.host,this.user,this.password);
let dbConn = await MongoDBConnector.getConnection(this.databaseName, this.connectionString);
let collection = dbConn.collection(this.tableName);
let bulkWriteReqArray = lodash.map(items, (item) => {
return {
Expand All @@ -29,4 +27,4 @@ class MongoDBDAO {
}
}

module.exports = MongoDBDAO;
module.exports = MongoDBDAO;