CouchDB通过文档字段内部联接?

编程入门 行业动态 更新时间:2024-10-28 02:34:59
本文介绍了CouchDB通过文档字段内部联接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个问题,我有2种文档,其中一个像这样:

I have a question, i have 2 kind of documents, one of them is like this:

{ "type": "PageType", "filename": "demo" "content": "zzz" }

和另一个类似的东西:

{ "type": "PageCommentType", "refFilename": "demo" "content": "some comment content" }

我需要发出包含ments字段的文档,该字段是我按条件PageType document filename == PageCommentType document refFilename字段链接的PageCommentType文档的数组。

i need to emit document that contains ments field which is array of PageCommentType documents that i link on condition PageType document filename == PageCommentType document refFilename fields.

{ "filename": "demo", "comments": [{}, {}, {}] }

有人对如何实施有何建议?

Anyone has any suggestions on how to implement it?

谢谢。

推荐答案

您需要查看排序规则 。使用文件名作为键和类型标识符在同一个视图中发射两者,以区分注释和原始内容:

You need view collation. Emit both within the same view, using the filename as the key and a type identifier to discriminate between comments and the original content:

function(doc) { if (doc.type == "PageType") emit([doc.filename,0],doc.content); if (doc.type == "PageCommentType") emit[doc.refFilename,1],doc.content); }

在查找文档 demo 及其注释,使用 startkey = [ demo,0] 和 endkey = [ demo,1] :您将获得页面内容以及所有注释。

When looking for the document demo and its comments, run a query with startkey=["demo",0] and endkey=["demo",1]: you will get the page content followed by all the comments.

一旦拥有了所需的所有数据,但是它的格式格式不正确,您快完成了。只需编写 _list 函数即可读取所有行,并输出具有所需结构/架构的最终JSON文档。

Once you have all the data you want, but it's not in the right format, you are almost done. Simply write a _list function to read all the rows and output the final JSON document with the structure/schema that you need.

更多推荐

CouchDB通过文档字段内部联接?

本文发布于:2023-10-15 00:40:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492722.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   文档   CouchDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!