Couchdb:访问show函数中的两个文档(Couchdb: Access to two documents in a shows function)

编程入门 行业动态 更新时间:2024-10-24 11:25:55
Couchdb:访问show函数中的两个文档(Couchdb: Access to two documents in a shows function)

我正在尝试创建一个需要访问两个文档的show函数:'doc'参考文档和另一个名为'users'的文档

我的功能如下:

function(doc,req){ var friends = doc.friends; var listFriends = []; for(int i = 0; i<friends.length; i++){ var phone = friends[i].phone; if(users[phone] != "" ){ listFriends.push(users[phone]); } } return JSON.stringify(listFriends); }

我不是专家也不是javascript也不是couchdb。 我的问题是,是否有可能以类似于代码的方式访问第二个文档(用户)? 到目前为止,它返回一个编译错误。

谢谢

I'm trying to create a show function which needs to access to two documents: The document in 'doc' reference and another document called 'users'

My function looks like:

function(doc,req){ var friends = doc.friends; var listFriends = []; for(int i = 0; i<friends.length; i++){ var phone = friends[i].phone; if(users[phone] != "" ){ listFriends.push(users[phone]); } } return JSON.stringify(listFriends); }

I'm not an expert nor javascript neither couchdb. My question is, Is it possible to access to the second document (users) in a similar way like in the code? So far it returns a compilation error.

Thanks

最满意答案

您只能在CouchDB show功能中访问一个文档。 您可以查看使用list函数,该函数适用于视图结果而不是文档。

创建一个视图,其中两个文档整理在一起(在视图顺序中并排显示),并且您获得的效果非常接近您希望使用show函数实现的效果。

You can only access one document in a CouchDB show function. You could look at using a list function, which works on view results instead of documents.

Create a view where the two documents collate together (appear side-by-side in the view order) and you achieve an effect pretty close to what you wanted to achieve with the show function.

更多推荐

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

发布评论

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

>www.elefans.com

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