使用 aws dms 仅按特定列将 mongodb 表迁移到 mysql

问题描述

我在 mongo 中有一个名为 reports 的架构和一个名为 totals 的集合。 其中的键看起来像:

 { "_id" : { "dt" : "2018-12-02","dt2" : "2018-04-08","num" : 1312312312 },"str" : 1 } 

我想使用 DMS 将此集合迁移到 aws 上的 MysqL 实例。该表应如下所示:

create table tab(
dt date,dt2 date,num bigint) 

目前,我使用具有简单规则的 dms:

{
  "rules": [
    {
      "rule-type": "transformation","rule-id": "1","rule-name": "1","rule-target": "table","object-locator": {
        "schema-name": "reports","table-name": "totals"
      },"rule-action": "rename","value": "tab","old-value": null
    },{
      "rule-type": "selection","rule-id": "2","rule-name": "2","rule-action": "include","filters": []
    }
  ]
}

结果不是我想要的:

MysqL [stats]> desc tab;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| _doc  | longtext | YES  |     | NULL    |       |
+-------+----------+------+-----+---------+-------+

MysqL [(none)]> select * from tab limit 1;
+------------------------------------------------------------------------------------------+
| _doc                                                                                     |
+------------------------------------------------------------------------------------------+
| { "_id" : { "dt" : "2018-12-02","str" : 1 } |
+------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

解决方法

端点需要有 nestingLevel=ONE; 而不是 nestingLevel=NONE;。 基本上它意味着将数据视为表格而不是文档。