如何使用嵌套分隔符拆分为子文档?

How to split into Sub Documents with Nesting separator?

我正在通过 Azure cosmos DB 数据迁移工具将数据从 SQL 迁移到 COSMOS DB

谁能帮忙迁移子文档中的数据,如何在嵌套分隔符中指定

SELECT TOP  5 P.ProjectDocumentId, P.ProjectId, PU.UpdatedByFullName
FROM [Docs].[ProjectDocuments] P
INNER JOIN [Docs].[ProjectDocumentUpdate] PU ON P.ProjectDocumentID = PU.ProjectDocumentID
WHERE P.ProjectDocumentId = '7DA0011B-7105-4B6C-AF13-12B5AC50B608'

结果:

Cosmos DB 中的预期文档:

{
  "ProjectDocumentId": "7da0011b-7105-4b6c-af13-12b5ac50b608",
  "ProjectId": "ed1e0e47-ff1c-47be-b5e9-c235aef76161",
  "ProjectDocumentUpdate": { 
    "UpdatedByFullName" : "Unnati" 
  }, { 
    "UpdatedByFullName" : "Eugene" 
  },
  { 
    "UpdatedByFullName" : "Meghana" 
  }             
} 

根据你的描述,你的需求不是简单的将嵌套 JSON 数据生成到 cosmos db.You 想要生成 JSON contains Json array group by some columns.Something 喜欢通过相同的 ProjectDocumentIdProjectId.

合并 UpdatedByFullName

根据我的测试和对 Migration Tool document 的一些研究,似乎 Import data from SQL SERVER feature 无法处理按某些列生成 json 数组组。

所以,我想出了一个由这种情况导致的解决方法: and this doc。我的示例数据如下:

SQL:

select s1.name,
'ageArr' = (
            SELECT
                age AS 'age' 
            FROM
                dbo.student as s2
            where s2.name = s1.name
            FOR JSON PATH)
from dbo.student as s1
group by s1.name
FOR JSON Path;

输出如下:

然后你有这样的json输出,这样你就可以简单地将它导入cosmos db。