使用部分文档更新在 Cosmos DB 中替换数组中的特定元素,而不知道其索引。

huangapple go评论55阅读模式
英文:

Replace specific element in array using partial document update in Cosmos DB without knowing it's index

问题

可以在 Cosmos 文档中使用部分文档更新来替换数组中特定元素而无需知道其索引吗?

给定示例的 JSON 文档,是否可以替换数组 "elements" 中名称为 "B" 的元素,而无需知道元素的索引,使用 Cosmos DB 中的部分文档更新?

{
    "elements": [
        {
            "name": "A",
            "value": 5
        },
        {
            "name": "B",
            "value": 3
        },
        {
            "name": "C",
            "value": 8
        }
    ]
}

Microsoft文档中未找到相关信息。

英文:

Is it possible to replace a specific element in an array in a Cosmos document using partial document update without knowing it's index?

Given the example json document, is it possible to replace the element in the array "elements" where name is "B", without knowing the index of the element using a partial document update in Cosmos DB?

{
    "elements": [
        {
            "name": "A",
            "value": 5
        },
        {
            "name": "B",
            "value": 3
        },
        {
            "name": "C",
            "value": 8
        }
    ]
}

No information found in the Microsoft documentation

答案1

得分: 1

不,PATCH 要求您传递需要更新的对象的特定索引,文档中有提到1。我们正在努力启用这一特定功能,但作为替代方案,您应该考虑条件性修补。

英文:

No, PATCH requires you to pass the specific index of the object needs to be updated and it is mentioned in the documentation. We are working on enabling this particular feature, However as an alternative, you should look at Conditional Patch

huangapple
  • 本文由 发表于 2023年2月23日 23:42:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547104.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定