Cosmos DB 替换嵌套对象中的字符串
Cosmos DB REPLACE strings in nested Object
我正在使用 Cosmos Data migration tool to migrate data between environments。在迁移过程中,我需要更新数据中网站的主机名。我能够通过这样的顶级对象数据查询轻松地做到这一点:
SELECT Farms["name"], Farms["farmerInfo"], REPLACE(Farms["websiteLink"], "thiswebsite", "newHostName") AS websiteLink FROM Farms
我的 Cosmos DB 数据的结构如下(数据仅供示例):
{
"name": "Red's Farm",
"websiteLink": "www.thiswebsite.com/goats/",
"farmerInfo": {
"name": "Bob",
"websiteLink": "www.thiswebsite.com/goats/",
"hasGoats": true,
"numGoats": 17
}
}
我实际上不需要修改任何顶级数据。我需要修改的数据在“farmerInfo”对象中。我尝试了一些东西,但我没有运气。如何使用 SQL api?
替换此对象中的字符串
我希望数据在迁移后看起来像这样:
{
"name": "Red's Farm",
"websiteLink": "www.thiswebsite.com/goats/",
"farmerInfo": {
"name": "Bob",
"websiteLink": "www.newHostName.com/goats/", <--- Updated data
"hasGoats": true,
"numGoats": 17
}
}
您可以在 SELECT
语句中使用 SELECT
语句来构建子对象。例如:
SELECT
c.name,
c.websiteLink,
(
SELECT
c.farmerInfo.name,
REPLACE(c.farmerInfo.websiteLink, "thiswebsite", "newHostName") AS websiteLink
) AS farmerInfo
FROM c
我正在使用 Cosmos Data migration tool to migrate data between environments。在迁移过程中,我需要更新数据中网站的主机名。我能够通过这样的顶级对象数据查询轻松地做到这一点:
SELECT Farms["name"], Farms["farmerInfo"], REPLACE(Farms["websiteLink"], "thiswebsite", "newHostName") AS websiteLink FROM Farms
我的 Cosmos DB 数据的结构如下(数据仅供示例):
{
"name": "Red's Farm",
"websiteLink": "www.thiswebsite.com/goats/",
"farmerInfo": {
"name": "Bob",
"websiteLink": "www.thiswebsite.com/goats/",
"hasGoats": true,
"numGoats": 17
}
}
我实际上不需要修改任何顶级数据。我需要修改的数据在“farmerInfo”对象中。我尝试了一些东西,但我没有运气。如何使用 SQL api?
替换此对象中的字符串我希望数据在迁移后看起来像这样:
{
"name": "Red's Farm",
"websiteLink": "www.thiswebsite.com/goats/",
"farmerInfo": {
"name": "Bob",
"websiteLink": "www.newHostName.com/goats/", <--- Updated data
"hasGoats": true,
"numGoats": 17
}
}
您可以在 SELECT
语句中使用 SELECT
语句来构建子对象。例如:
SELECT
c.name,
c.websiteLink,
(
SELECT
c.farmerInfo.name,
REPLACE(c.farmerInfo.websiteLink, "thiswebsite", "newHostName") AS websiteLink
) AS farmerInfo
FROM c