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
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
MONGODB_USERNAME: process.env.MONGODB_USERNAME,
MONGODB_PASSWORD: process.env.MONGODB_PASSWORD,
MONGODB_ENDPOINT: process.env.MONGODB_ENDPOINT,
MONGODB_URL: process.env.MONGODB_URL,
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
AWS_REGION: process.env.AWS_REGION,
Expand Down
2 changes: 1 addition & 1 deletion 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);
this.dynamodbEvalLimit = dynamodbEvalLimit || 100;
this.filterExpression = null;
this.expressionAttributeNames = null;
Expand Down
12 changes: 9 additions & 3 deletions src/connectors/MongoDBConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ let client;

class MongoDBConnector {

static getConnection(database,host,user,password) {
static getConnection(database, targetConnectionOptions) {
return new Promise(async (resolve, reject) => {
try {
if (client) {
resolve(client.db(database));
} else {
let url = 'mongodb://' + user + ':' + password + '@' + host;
client = new MongoClient(url,{ useNewUrlParser: true });
let url = "";
// Adds the option to pass the URL as a whole
if (targetConnectionOptions.url)
url = targetConnectionOptions.url;
else {
url = 'mongodb://' + targetConnectionOptions.user + ':' + targetConnectionOptions.password + '@' + targetConnectionOptions.host;
}
client = new MongoClient(url, { useNewUrlParser: true });
await client.connect();
resolve(client.db(database));
}
Expand Down
9 changes: 4 additions & 5 deletions src/dao/MongoDBDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ const lodash = require('lodash');
const MongoDBConnector = require('./../connectors/MongoDBConnector');

class MongoDBDAO {
constructor(tableName, databaseName,host,user,password) {

constructor(tableName, databaseName, targetConnectionOptions) {
this.tableName = tableName;
this.databaseName = databaseName;
this.host = host;
this.user = user;
this.password = password;
this.targetConnectionOptions = targetConnectionOptions;
}

async intertOrUpdateItems(items) {
let dbConn = await MongoDBConnector.getConnection(this.databaseName,this.host,this.user,this.password);
let dbConn = await MongoDBConnector.getConnection(this.databaseName, this.targetConnectionOptions);
let collection = dbConn.collection(this.tableName);
let bulkWriteReqArray = lodash.map(items, (item) => {
return {
Expand Down