gpt4 book ai didi

couchdb - 在 couchdb View 中组合多个文档

转载 作者:行者123 更新时间:2023-12-04 23:21:38 24 4
gpt4 key购买 nike

在 couchdb 中,我需要以以下格式表示一些数据,一个引用数组内其他文档的外部容器。

我想将这些文档分开,因为我需要单独管理它们的冲突。

{
"_id" : "1"'
"type" : "container",
"items" : [ "1", "2", "3"]
}


{
"_id" : "2",
"value": "a"
"type" : "item"
}


{
"_id" : "3",
"value": "b"
"type" : "item"
}


{
"_id" : "4",
"value": "c"
"type" : "item"
}

我想以以下格式输出数据 View 。
{
"_id" : "1"'
"type" : "container",
"items" : [
{
"_id" : "2",
"value": "a"
"type" : "item"
},
{
"_id" : "3",
"value": "b"
"type" : "item"
},
{
"_id" : "4",
"value": "c"
"type" : "item"
}
]

}

解决这个问题的最佳方法是什么?

最佳答案

您可以使用 couchdb linked documents 实现此目的

这是 View 的样子

  function(doc){
if(doc.items)
doc.items.forEach(function(item){
emit(doc._id,{_id:item});
})
}

现在您可以使用 include_docs=true 查询 View 参数,你应该有想要的结果。

关于couchdb - 在 couchdb View 中组合多个文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24264898/

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