DataX案例,MongoDB数据导入HDFS与MySQL
以下是一个简化的DataX例子,用于从MongoDB导入数据到HDFS和MySQL。
- 配置文件
job-mongodb2hdfs.json
:
{
"job": {
"setting": {
"speed": {
"channel": 1
}
},
"content": [
{
"reader": {
"name": "mongodbreader",
"parameter": {
"address": ["mongodb://username:password@localhost:27017"],
"db": "test_db",
"collection": "test_collection",
"column": ["id", "name", "age"]
}
},
"writer": {
"name": "hdfswriter",
"parameter": {
"path": "/user/hive/warehouse/test_hdfs",
"fileName": "imported_from_mongodb",
"writeMode": "append",
"fieldDelimiter": ","
}
}
}
]
}
}
- 配置文件
job-mongodb2mysql.json
:
{
"job": {
"setting": {
"speed": {
"channel": 1
}
},
"content": [
{
"reader": {
"name": "mongodbreader",
"parameter": {
"address": ["mongodb://username:password@localhost:27017"],
"db": "test_db",
"collection": "test_collection",
"column": ["id", "name", "age"]
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"username": "root",
"password": "password",
"writeMode": "insert",
"connection": [
{
"jdbcUrl": "jdbc:mysql://localhost:3306/test_db",
"table": ["test_table"]
}
]
}
}
}
]
评论已关闭