This Node.js script is designed to transfer data from a MySQL database to a MongoDB database. It allows you to configure the database connections and select specific columns to transfer. The script is useful for migrating data from MySQL to MongoDB or for maintaining synchronized data between the two databases which will automatically Zinc data in every 10 mints by default.
Follow these instructions to set up and run the script on your local machine.
-
Node.js and npm: Make sure you have Node.js and npm installed on your machine. If not, you can download and install them from Node.js official website.
-
Access to MySQL and MongoDB: You'll need access to a MySQL database from which you want to transfer data and a MongoDB database where you want to store the transferred data.
-
Clone the Repository:
git clone https://github.com/nandhuz-coder/MySql-to-mongodb cd Mysql-to-mongodb
-
Install Dependencies:
npm install
Edit the config.json
file in the project directory to configure your database connections and column mapping settings. The configuration file should look something like this:
{
"database": {
"host": "your_mysql_host",
"user": "your_mysql_user",
"databaseName": "your_mysql_database_name",
"collection": "your_mongodb_collection_name",
"mongodb": "mongodb://your_mongodb_host:your_mongodb_port/your_mongodb_database"
},
"mysqlQueryColumns": [
{
"name": "identifier",
"type": "String"
},
{
"name": "accounts",
"type": "String"
},
{
"name": "`group`",
"type": "String"
}
],
"fetch_time": 600000,
"table_name": "tablename"
}
- Add password; If Sql database have password.
"password": "your_mysql_password",
. - Enclose in
`
for keyword as column name. - Add more columns as needed.
- If identifier name is changed. change it also from sql.js.
To run the script, follow these steps:
-
Navigate to Your Project Directory:
Open your terminal and navigate to the directory where your Node.js script is located. Use the
cd
command to change directories.cd /path/to/MySql-to-mongodb
-
Run the Script:
Once you are in the project directory, you can run the script using the following command, Before that make sure that dependences are downloaded:
npm start
- Node.js - JavaScript runtime
- mysql2 - MySQL client for Node.js
- mongoose - MongoDB object modeling tool
For detailed security information, including how to report security issues and security best practices, please refer to our Security Policy.
For any security-related questions or concerns, please reach out to our security team at dev.nandhagopan@gmail.com.
This project is licensed under the MIT License - see the LICENSE.md file for details.