incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Lehnardt <...@apache.org>
Subject Re: Loading another object to return in a view!
Date Sat, 12 Apr 2008 09:17:32 GMT
Heya Sebastian,
On Apr 12, 2008, at 01:46, Guby wrote:
> Maybe I wasn't clear.
> It is nothing ajax like.
> What I am trying to accomplish is that when document X is indexed by  
> the view server, it maps parts of document Y in addition to itself.
> I have seen the CouchDB class being used in the test suite in the  
> couchDB interface, so I thought that was something that also would  
> be available in the views?! But it is not?

In addition to Chris' answer: the CouchDB object is just a wrapper  
object that uses AJAX to talk to CouchDB over HTTP. Again, this is not  
available from within views. And while this could be added, it sounds  
more like a hassle than something we'd actually want to support.

What exactly are you trying to do here? Maybe you are still trapped (I  
know I often am) in the relational world and things could be solved in  
a 'CouchDB way' for you.

Cheers
Jan
--


> Is there no way for a view, indexing the document X, to access the  
> database and get some info?
>
> Best regards
> S
>
>
>
>
>
> On Apr 11, 2008, at 8:11 PM, Jan Lehnardt wrote:
>
>> 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