gpt4 book ai didi

Couchbase N1QL : Update on nested Documents

转载 作者:行者123 更新时间:2023-12-04 22:30:22 26 4
gpt4 key购买 nike

当有这样的嵌套文档时:

{
"blog": "testblog1",
"user_id": 41,
"comments": [
{
"comment": "testcomment1",
"user_id": 883
},
{
"comment": "testcomment2",
"user_id": 790
}
]
}

可以使用 N1QL 执行更新操作以向子文档添加额外字段吗?

我想将字段 "ranking" : "top comment" 添加到带有注释 testcomment2 的子文档中:
{
"blog": "testblog1",
"user_id": 41,
"comments": [
{
"comment": "testcomment1",
"user_id": 883
},
{
"comment": "testcomment2",
"user_id": 790,
"ranking" : "top comment"
}
]
}

站点注释:以下语句将向 Collection Blog 上的根文档添加一个字段:
UPDATE Blog SET rank = "top blog" WHERE blog = "testblog1";

最佳答案

是的,您可以在 N1QL 中执行以下操作:

更新博客
SET c.ranking = "top comment"FOR c IN 评论 WHEN c.comment = "testcomment2"END
WHERE 博客 = "testblog1"

关于Couchbase N1QL : Update on nested Documents,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29581646/

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