gpt4 book ai didi

join - 如何在 couchDB View 中引用其他文档(加入类似功能)

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

我们有一个 XML 数据库的 CouchDB 表示,我们用它来驱动基于 javascript 的前端来操作 XML 文档。基本结构是一个简单的 3 级层次结构。 IE。

A -> B -> C

A:父文件(A 类)
B:任意数量的父类型 A 的子文档
C:任意数量的父类型 B 的子文档

我们在 CouchDB 中用 type 表示这 3 种文档类型。属性:

例如

{
"_id":"llgc-id:433",
"_rev":"1-3760f3e01d7752a7508b047e0d094301",
"type":"A",
"label":"Top Level A document",
"logicalMap":{
"issues":{
"1":{
"URL":"http://hdl.handle.net/10107/434-0",
"FILE":"llgc-id:434"
},
"2":{
"URL":"http://hdl.handle.net/10107/467-0",
"FILE":"llgc-id:467"
etc...
}
}
}
}


{
"_id":"llgc-id:433",
"_rev":"1-3760f3e01d7752a7508b047e0d094301",
"type":"B",
"label":"a B document",
}

我想要做的是生成一个 View ,它像 A 类型一样返回文档,但在 logicalMap 列表中包含来自 B 文档的标签属性,例如
{
"_id":"llgc-id:433",
"_rev":"1-3760f3e01d7752a7508b047e0d094301",
"type":"A",
"label":"Top Level A document",
"logicalMap":{
"issues":{
"1":{
"URL":"http://hdl.handle.net/10107/434-0",
"FILE":"llgc-id:434",
"LABEL":"a B document"
},
"2":{
"URL":"http://hdl.handle.net/10107/467-0",
"FILE":"llgc-id:467",
"LABEL":"another B document"
etc...
}
}
}
}

我正在努力寻找执行此操作的最佳方式。不过看起来它应该相当简单!

最佳答案

查看 http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views#Linked_documents 中的“链接文档”部分

function(doc) {
//....
if (doc.logicalMap.issues) {
for (var i in doc.logicalMap.issues) {
emit([doc._id,doc.logicalMap.issues[i]['FILE']],
{_id: doc.logicalMap.issues[i]['FILE']});
}
}
}

(未经测试)

然后用 include_docs=true 查询

关于join - 如何在 couchDB View 中引用其他文档(加入类似功能),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4625187/

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