Data_web(八)mysql增量同步到mongodb

1.mongdb连接
连接方式如下(重要!!!!,账号密码必须建立在db下面,如果默认再admin下面,导致无法切换库,连接报错)
在这里插入图片描述

2.mysql增量同步到mongodb的json如下,(可以参考先前文章mysql增量时间同步方式)

{
  "job": {
    "setting": {
      "speed": {
        "channel": 3,
        "byte": 1048576
      },
      "errorLimit": {
        "record": 0,
        "percentage": 0.02
      }
    },
    "content": [
      {
        "reader": {
          "name": "mysqlreader",
          "parameter": {
            "username": "123",
            "password": "123",
            "connection": [
              {
                "jdbcUrl": [
                  "jdbc:mysql://192.168.1.101:3306/test"
                ],
                "querySql": [
                  "SELECT 'test'as source,(CASE when gateway_id=9 then 'test' ELSE 'tnc' end) as app_code,target ,target_account_id as account_id, null as user_name, sms_content as content, send_time ,send_id  as outer_id FROM  qfc_mcs_send_mass_info where sms_type = '3' and status in (3,4)  and send_time >= FROM_UNIXTIME(${lastTime}) and send_time < FROM_UNIXTIME(${currentTime});"
                ]
              }
            ]
          }
        },
        "writer": {
          "name": "mongodbwriter",
          "parameter": {
            "address": [
              "192.168.1.100:27017"
            ],
            "userName": "username",
            "userPassword": "password",
            "dbName": "DBname",
            "collectionName": "message_send_info",
            "column": [
              {
                "name": "sourceSystem",
                "type": "String"
              },
              {
                "name": "app_code",
                "type": "String"
              },
              {
                "name": "target",
                "type": "String"
              },
              {
                "name": "account_id",
                "type": "Long"
              },
              {
                "name": "user_name",
                "type": "String"
              },
              {
                "name": "content",
                "type": "String"
              },
              {
                "name": "send_time",
                "type": "Date"
              },
              {
                "name": "outer_id",
                "type": "Long"
              }
            ],
            "upsertInfo": {
              "isUpsert": false,
              "upsertKey": ""
            }
          }
        }
      }
    ]
  }
}

如果需要更新isUpsert改写true upsertKey为更新的字段
3.字段参考

DataX 内部类型MongoDB 数据类型
Longint, Long
Doubldouble
Stringstring, array
Datedate
Bytesbytes
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值