如何在 couchDB 视图中引用其他文档(加入类似功能)
我们有一个 XML 数据库的 CouchDB 表示,我们用它来支持基于 javascript 的前端来操作 XML 文档。基本结构是一个简单的三级层次结构。即
A-> B-> C
- A:父文档(类型 A)
- B:任意数量的父类型 A 的子文档
- C:任意数量的父类型 B 的子文档
我们用 type
属性在 CouchDB 中表示这 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",
}
我想要做的是生成一个视图,该视图返回与 A 类型类似的文档,但在逻辑映射列表中包含来自 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...
}
}
}
}
我正在努力寻找执行此操作的最佳方法。看起来应该很简单!
We have a CouchDB representation of an XML database which we use to power a javascript based front-end for manipulating the XML documents. The basic structure is a simple 3 level hierarchy. i.e.
A -> B -> C
- A: Parent document (type A)
- B: any number of child documents of parent type A
- C: any number of child documents of parent type B
We represent these 3 document types in CouchDB with a type
attribute:
e.g.
{
"_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",
}
What I want to do is produce a view which returns documents just like the A type but includes the label attribute from the B document within the logicalMap list e.g.
{
"_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...
}
}
}
}
I'm struggling to get my head around the best way to perform this. It looks like it should be fairly simple though!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 http://wiki.apache.org/couchdb/ 中的“链接文档”部分Introduction_to_CouchDB_views#Linked_documents
(未经测试)
然后使用
include_docs=true
进行查询Have a look at the "Linked Document' Section in http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views#Linked_documents
(untested)
Then query with
include_docs=true