在沙发数据库视图中合并多个文档

编程入门 行业动态 更新时间:2024-10-20 07:39:56
本文介绍了在沙发数据库视图中合并多个文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在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}); }) }

现在您可以使用 include_docs = true 参数,您应该会得到所需的结果。

now you can query the view with include_docs=true parameter and you should have the desired result.

更多推荐

在沙发数据库视图中合并多个文档

本文发布于:2023-10-30 04:20:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541746.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   视图   沙发   文档   数据库

发布评论

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

>www.elefans.com

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