天天看點

DataWorks百問百答64:資料內建如何同步Mongodb不同資料類型?

mongodb源端原始資料如下(資料無實際場景):

DataWorks百問百答64:資料內建如何同步Mongodb不同資料類型?

  • 同步一層子屬性

例1:同步id:

{

"name": "id",

"type": "string"

}

例2:同步services:

"name": "services",

"type": "object"

},

  • 同步複雜類型的子屬性:

同步services下的子屬性optional:

"name": "services.optional",

"type": "document.string"

注意:array類型無法取到array下的具體資料,需要作為整體同步

          type值需要小寫。

  • 多個字段合并成一個json串:

使用MongoDBReader插件讀出資料時,支援将MongoDB裡document中多個字段合并成一個json串;

舉例來說将Mongo中的字段導入到ODPS,有字段如下(下文均省略了value使用key來代替整個字段)的三個document,其中 a b 是所有doc均有的公共字段, x_n是不固定字段:

   doc1:a b x_1 x_2

   doc2:  a b x_2 x_3 x_4

   doc3:  a b x_5

需要一一對應的字段在配置檔案裡明确指出,需要合并的字段則需另取名稱(不可與document中已存在字段同名),并指定類型為 "combine" ,如:

"column": [

{

 "name": "a",

 "type": "string",

},

  "name": "b",

  "type": "string",

    "name": "doc",

"type": "combine",

 }

]

最終導出到ODPS效果為:

odps_column1 odps_column2 odps_column3
a b {x_1,x_2}
{x_1,x_2,x_3}
{x_5}

DataWorks百問百答曆史記錄

請點選這裡檢視>>

更多DataWorks技術和産品資訊,歡迎加入

【DataWorks釘釘交流群】