Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

migrate mongodb table by specefic columns only to mysql using aws dms

I have a schema named reports in mongo and a collection named totals. The keys in it looks like:

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

I would like to use DMS to migrate this collection into mysql instance on aws. The table should look like:

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

Currently, I'm using dms with simple rule:

{
  "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",
      "object-locator": {
        "schema-name": "reports",
        "table-name": "totals"
      },
      "rule-action": "include",
      "filters": []
    }
  ]
}

The result is not what I wanted:

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", "dt2" : "2018-04-08", "num" : 1312312312 }, "str" : 1 } |
+------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
question from:https://stackoverflow.com/questions/65901424/migrate-mongodb-table-by-specefic-columns-only-to-mysql-using-aws-dms

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Endpoint needed to have nestingLevel=ONE; instead of nestingLevel=NONE;. Basically it means look at the data as a table instead of a document.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...