开发者

Couchdb: Access to two documents in a shows function

开发者 https://www.devze.com 2023-04-07 02:17 出处:网络
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\'

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 fun开发者_StackOverflow中文版ction 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号