在沙发数据库视图中合并多个文档 [英] combine multiple documents in a couchdb view
本文介绍了在沙发数据库视图中合并多个文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在ouchdb中,我需要以以下格式表示一些数据,即一个外部容器,该外部容器引用数组中的其他文档。
In couchdb, I need to represent some data in the following format, a outer container that references other documents inside an array.
我想将这些文档分开
{
"_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"
}
我想以以下格式输出数据视图。
I want to output a view of the data in the following format.
{
"_id" : "1"'
"type" : "container",
"items" : [
{
"_id" : "2",
"value": "a"
"type" : "item"
},
{
"_id" : "3",
"value": "b"
"type" : "item"
},
{
"_id" : "4",
"value": "c"
"type" : "item"
}
]
}
解决这个问题的最佳方法是什么?
Whats the best way to approach this?
推荐答案
您可以使用 couchdb链接的文件
视图的外观如下
function(doc){
if(doc.items)
doc.items.forEach(function(item){
emit(doc._id,{_id:item});
})
}
现在您可以使用<$ c查询视图$ c> include_docs = true 参数,您应该会得到所需的结果。
now you can query the view with include_docs=true
parameter and you should have the desired result.
这篇关于在沙发数据库视图中合并多个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文