couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Lehnardt <...@prima.de>
Subject Re: Loading another object to return in a view!
Date Fri, 11 Apr 2008 23:11:44 GMT
Views do not run in the context of a browser. So you don't have any  
AJAX features there. The map function gets executed in a very isolated  
environment.

You could hook up a different language interpreter for your views that  
let's you access external resources, but you'd be pretty much on your  
own support-wise.

Cheers
Jan
--


On 12 Apr 2008, at 00:26, Guby <guby.mail@gmail.com> wrote:

> 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