将一对多批量导入 DocumentDB 集合

Bulk import one to many into DocumentDB collection

我有两个 SQL Azure 表,我正在通过在 DocumentDB 中导入将它们合并到一个集合中。这是数据的样子。为了简洁起见,我进行了更改。

contact
- contact_id
- name
- ...

contact_attribute (max 10 records per user avg ~3)
- contact_attribute_id
- contact_id
- attribute_name
- attribute_value
- ...

我希望新的 JSON 文档看起来像这样:

{
    Id: "contact_id",
    name: "name",
    more: "...",
    attributes {
        "name": "value",
        "name2": "val2",
        "..." : "..."
    }
}

有没有一种方法可以通过 DocumentDB 数据迁移工具来编写 SQL 查询,运行?

又高又瘦的 table 像您的 table 这样的属性是出了名的难以管理 SQL。我认为仅使用数据迁移工具中的 SQL 不可能完成您的要求。我对 Azure Table 不够熟悉,无法对哪种方法最好有强烈的看法,但我想到了两种方法:

  1. 大批量。下载整个 Azure Table 数据集,修改成你想要的形状,然后批量上传到 DocumentDB。

  2. 一次一个联系人。为一个联系人查询您的父级 table,然后为它的所有属性查询属性 table,然后将联系人写入 DocumentDB。对所有联系人重复此操作。