mongosynctosql
v1.0.6
Published
================
Downloads
15
Maintainers
Readme
mongosynctosql
================
This package, mongosynctosql
, is a simple utility to synchronize data from a MongoDB database to a MySQL database. It is built using Node.js and the mongodb
and mysql
npm packages.
Installation
Usage
To use this package, you will need to provide the following configuration:
mongoConfig
: an object containing the MongoDB connection information, including the Mongo URL, database name, and collection name.mysqlConfig
: an object containing the MySQL connection information, including the host, user, password, database name, and table name.fieldsThatYouMigrateToMySqlFromMongo
: an array of objects, each containing the field name conversion, the field name in MongoDB, and the conversion type.
Here is an example of how to use this package:
const syncDataFromMongoToMySQL = require('mongosynctosql');
const mongoConfig = {
mongoUrl:"yourmongoconnectionstring",
mongoDbName:"yourmongodbname",
mongoCollectionName:"yourmongocollectionname"
}
const mysqlConfig = {
mysqlConfiguration:{
host: 'host',
user: 'username',
password: 'yourpassword',
database: 'yourdbname'
},
mySqlTableName:"yourtablename"
}
const fieldsThatYouMigrateToMySqlFromMongo = [
{
fieldNameConversion:"id",
fieldName:"_id",
conversionType:"String"
},
{
fieldName:"name",
conversionType:"String"
},
{
fieldName:"speciality",
conversionType:"String"
}
]
syncDataFromMongoToMySQL(mongoConfig, mysqlConfig,fieldsThatYouMigrateToMySqlFromMongo,numberOfDocuments)
.then(() => {
console.log('Data synchronization completed successfully');
})
.catch((err) => {
console.error('Error during data synchronization:', err);
});