我正在尝试创建一个需要访问两个文档的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.
更多推荐
发布评论