gpt4 book ai didi

node.js - Cosmos DB 通过部分文档更新进行增量

转载 作者:行者123 更新时间:2023-12-02 07:42:34 25 4
gpt4 key购买 nike

https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update#supported-operations说我可以使用“increment”来增加数据库中的值,但是这段代码

const operations =
[
{ op: 'increment', path: '/public/inventory/irradish', value: irradish},
{ op: 'increment', path: '/public/inventory/sunmelon', value: sunmelon},
{ op: 'set', path: '/map/garden/lastUse', value: time}
];
const { resource: updated } = await container
.item(
id = email,
partitionKeyValue = email
)

抛出此错误:

错误:消息:{“错误”:[“补丁请求中的补丁操作'op'属性值无效:'增量'”]}ActivityId:f1bb8b88-ab68-4f2b-b244-8b021b0d9021,...

如何增加?

最佳答案

您需要使用上面回答的“incr”。

但是对于文档来说,增量只是一个操作。 Node SDK中的样本存储库说明了如何进行增量操作,

const multipleOperations: PatchOperation[] = [
{
op: "add",
path: "/aka",
value: "MeFamily",
},
{
op: "replace",
path: "/lastName",
value: "Jose",
},
{
op: "remove",
path: "/parents",
},
{
op: "set",
path: "/address/zip",
value: 90211,
},
{
op: "incr",
path: "/address/zip",
value: 5,
},
];
const { resource: patchSource2 } = await container.item(patchId!).patch(multipleOperations);
if (patchSource2) {
console.log(`Patched ${JSON.stringify(patchSource)} to new ${JSON.stringify(patchSource2)}.`);
}

关于node.js - Cosmos DB 通过部分文档更新进行增量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73043486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com