incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guby <guby.m...@gmail.com>
Subject Loading another object to return in a view!
Date Fri, 11 Apr 2008 22:26:44 GMT
Dear CouchDB developers and users.
I have another view related question.

What I am trying to do is this:
Every document of type X has stored a reference to document Y. Based  
on certain parameters in X i decide whether or not to load and return  
document Y from the DB.

The view code I am trying to use looks something like this:

function(doc){
	if (doc.class == "OfTypeX" && doc.an_attribute == true){
		var db = new CouchDB("mydb");
		var doc2 = db.open(doc.id_of_object_Y);
		map([doc.another_attribute, doc.id_of_Y], doc2);
	}
}

Whenever I include the line "var db = new CouchDB('mydb');" in my view  
everything stops... It works perfectly in the Javascript Shell though!
Any ideas?
Aren't you allowed to access the DB directly from a view?
Is there a way to access other documents than the one being passed in  
to the view, from a view?
I realize though that these kinds of views might lead to stale data as  
the view index doesn't get updated if the document Y gets updated, but  
that is all right in my case.

Best regards
Sebastian

Mime
View raw message