# DB Converter - MySQL to MongoDB | MongoDB to MySQL
![db-converter-mysql-to-mongodb-mongodb-to-mysql](dbconverter_main_img.png)
This project is a python library that facilitates data conversion between MongoDB and MySQL databases.
## Installation
You can use the following command to install the project:
```bash
pip install db-converter
```
## Usage
By using this project, you can convert a specific table from a MySQL database to a MongoDB collection.
You can also convert a specific collection from a MongoDB database to a MySQL table.
```python
from dbconverter.converter import Converter
# DW bilgileri
DATAWAREHOUSE_HOST = "000.00.0.00"
DATAWAREHOUSE_USER = "admin"
DATAWAREHOUSE_PASSWORD = "password"
port_number = 8080
uri = "mongodb+srv://admin:password!@cluster0.smovknl.mongodb.net/?retryWrites=true&w=majority"
mysql_bilgilerim = {'host': DATAWAREHOUSE_HOST, 'user': DATAWAREHOUSE_USER, 'password': DATAWAREHOUSE_PASSWORD,
'port': port_number, 'database': 'your_db_name'}
my_converter = Converter(uri, **mysql_bilgilerim)
my_converter.mysql_to_mongodb('test_table')
```
## Used Libraries
- `pandas`: Used for working with data frames.
- `pymongo`: Used for communicating with MongoDB.
- `pymysql`: Used for connecting to the MySQL database.
## Classes and Methods
`Converter`
- `__init__(self, mongo_uri, **kwargs)`: Creates an instance of Converter by taking MongoDB and MySQL connection information.
- `df_to_json(df) -> list` : Converts a DataFrame into JSON objects.
- `mysql_to_mongodb(self, table_name=None)` : Converts data from a specific MySQL table to a MongoDB collection.
`MongoDb`
- `__init__(self, uri)`: Establishes a connection to MongoDB.
- `connect(self)` : Connects to the MongoDB server.
- `insert_data(self, json_data, collection)` : Inserts JSON data into the specified collection.
- `get_data(self, collection, query=None)` : Retrieves data from the specified collection.
`MySQLConnector`
- `__init__(self, host, user, password, port_number, database)` : Establishes a connection to MySQL.
- `connect(self)` : Connects to the MySQL database.
`disconnect(self)` : Closes the connection.
`fetch_data(self, table) -> pd.DataFrame` : Fetches data from the specified table and converts it into a DataFrame.
## Licence
This project is licensed under the MIT License. See the LICENSE file for more information.
Raw data
{
"_id": null,
"home_page": "",
"name": "db-converter",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "python,mongodb,mysql,database,MySQL to MongoDB,MongoDB to MySQL,data migration",
"author": "dilsizyazilimci (Mert Celikan)",
"author_email": "celikanmert@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d4/c3/fc31f62f739247d39489cac55e24c9b225db78c156eebad54d5089e9bcb4/db-converter-0.2.2.tar.gz",
"platform": null,
"description": "\n# DB Converter - MySQL to MongoDB | MongoDB to MySQL\n![db-converter-mysql-to-mongodb-mongodb-to-mysql](dbconverter_main_img.png)\n\nThis project is a python library that facilitates data conversion between MongoDB and MySQL databases.\n\n## Installation\n\nYou can use the following command to install the project:\n\n```bash\npip install db-converter\n```\n\n## Usage\n\nBy using this project, you can convert a specific table from a MySQL database to a MongoDB collection. \n\nYou can also convert a specific collection from a MongoDB database to a MySQL table.\n\n```python\nfrom dbconverter.converter import Converter\n\n# DW bilgileri\nDATAWAREHOUSE_HOST = \"000.00.0.00\"\nDATAWAREHOUSE_USER = \"admin\"\nDATAWAREHOUSE_PASSWORD = \"password\"\nport_number = 8080\n\nuri = \"mongodb+srv://admin:password!@cluster0.smovknl.mongodb.net/?retryWrites=true&w=majority\"\nmysql_bilgilerim = {'host': DATAWAREHOUSE_HOST, 'user': DATAWAREHOUSE_USER, 'password': DATAWAREHOUSE_PASSWORD,\n 'port': port_number, 'database': 'your_db_name'}\n\nmy_converter = Converter(uri, **mysql_bilgilerim)\nmy_converter.mysql_to_mongodb('test_table')\n```\n\n## Used Libraries\n- `pandas`: Used for working with data frames.\n- `pymongo`: Used for communicating with MongoDB.\n- `pymysql`: Used for connecting to the MySQL database.\n\n\n## Classes and Methods\n`Converter`\n- `__init__(self, mongo_uri, **kwargs)`: Creates an instance of Converter by taking MongoDB and MySQL connection information.\n- `df_to_json(df) -> list` : Converts a DataFrame into JSON objects. \n- `mysql_to_mongodb(self, table_name=None)` : Converts data from a specific MySQL table to a MongoDB collection.\n\n`MongoDb`\n- `__init__(self, uri)`: Establishes a connection to MongoDB.\n- `connect(self)` : Connects to the MongoDB server.\n- `insert_data(self, json_data, collection)` : Inserts JSON data into the specified collection.\n- `get_data(self, collection, query=None)` : Retrieves data from the specified collection.\n\n`MySQLConnector`\n- `__init__(self, host, user, password, port_number, database)` : Establishes a connection to MySQL.\n- `connect(self)` : Connects to the MySQL database.\n`disconnect(self)` : Closes the connection.\n`fetch_data(self, table) -> pd.DataFrame` : Fetches data from the specified table and converts it into a DataFrame.\n\n## Licence\n\nThis project is licensed under the MIT License. See the LICENSE file for more information.\n",
"bugtrack_url": null,
"license": "",
"summary": "Data migration. MongoDB to MySQL - MySQL to MongoDB",
"version": "0.2.2",
"project_urls": null,
"split_keywords": [
"python",
"mongodb",
"mysql",
"database",
"mysql to mongodb",
"mongodb to mysql",
"data migration"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d4c3fc31f62f739247d39489cac55e24c9b225db78c156eebad54d5089e9bcb4",
"md5": "aca55b3a403a3feb02cd250766be75f0",
"sha256": "a63c548312abefcfe2387ad69458b850d50a6d9c49bae21c377a9711d76fcd2e"
},
"downloads": -1,
"filename": "db-converter-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "aca55b3a403a3feb02cd250766be75f0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5424,
"upload_time": "2023-10-08T16:31:05",
"upload_time_iso_8601": "2023-10-08T16:31:05.923761Z",
"url": "https://files.pythonhosted.org/packages/d4/c3/fc31f62f739247d39489cac55e24c9b225db78c156eebad54d5089e9bcb4/db-converter-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-08 16:31:05",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "db-converter"
}