You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Mike Keen <mk...@visiture.com> on 2010/03/01 16:41:25 UTC
Relational-esque behavior in CouchDB
Hey,
I am managing a database that has hundreds of thousands of documents (so far), all containing a field called "keyword_id". I am not storing the "keyword_name" inside of each individual document for several reasons. The biggest reason being that the name could change at any time, but I don't want old documents to become outdated. I still want them to be associated with one another.
Anyway, I am wondering if there is currently a special function within the CouchDB JavaScript view server to pull data across views. I have a view that serves as an index of keyword_ids/names. I also have another view that aggregates keyword data, but can't return the keyword names. Currently, I just run two requests to CouchDB. One to retrieve all aggregated keyword data, and another to retrieve the relevant keyword names as they relate to the ids.
I am assuming that the way I am doing it is currently the best way, but wanted to see if it was possible to run something like:
function(doc) {
var keyword_name = view("/lu_persistence/_design/keywords/_view/keyword_id_name_map?key=" + doc.keyword_id);
doc.keyword_name = keyword_name;
emit(null, doc);
}
Maybe I'm just nuts, but I think this would be ridiculously useful. And if it's already in there, and someone could point me in the right direction, I'd greatly appreciate it.
Thanks a million,
Mike Keen
Re: Relational-esque behavior in CouchDB
Posted by Paul Davis <pa...@gmail.com>.
Mike,
It'd be quite difficult if not impossible to be able to build the
derivative view incrementally. Allowing map functions to pull data
from a random location would break the referential transparency
requirement.
HTH,
Paul Davis
On Mon, Mar 1, 2010 at 10:41 AM, Mike Keen <mk...@visiture.com> wrote:
> Hey,
>
> I am managing a database that has hundreds of thousands of documents (so far), all containing a field called "keyword_id". I am not storing the "keyword_name" inside of each individual document for several reasons. The biggest reason being that the name could change at any time, but I don't want old documents to become outdated. I still want them to be associated with one another.
>
> Anyway, I am wondering if there is currently a special function within the CouchDB JavaScript view server to pull data across views. I have a view that serves as an index of keyword_ids/names. I also have another view that aggregates keyword data, but can't return the keyword names. Currently, I just run two requests to CouchDB. One to retrieve all aggregated keyword data, and another to retrieve the relevant keyword names as they relate to the ids.
>
> I am assuming that the way I am doing it is currently the best way, but wanted to see if it was possible to run something like:
>
> function(doc) {
> var keyword_name = view("/lu_persistence/_design/keywords/_view/keyword_id_name_map?key=" + doc.keyword_id);
> doc.keyword_name = keyword_name;
> emit(null, doc);
> }
>
> Maybe I'm just nuts, but I think this would be ridiculously useful. And if it's already in there, and someone could point me in the right direction, I'd greatly appreciate it.
>
> Thanks a million,
> Mike Keen
>
Re: Relational-esque behavior in CouchDB
Posted by J Chris Anderson <jc...@gmail.com>.
On Mar 1, 2010, at 9:44 AM, Mike Keen wrote:
> Chris,
>
> It's not a feature of our application. It's a consequence of dealing with the Google AdWords API.
>
The relational model strikes back! ;)
> Thanks anyway,
> Mike
>
> On Mar 1, 2010, at 11:55 AM, J Chris Anderson wrote:
>
>>
>> On Mar 1, 2010, at 7:41 AM, Mike Keen wrote:
>>
>>> Hey,
>>>
>>> I am managing a database that has hundreds of thousands of documents (so far), all containing a field called "keyword_id". I am not storing the "keyword_name" inside of each individual document for several reasons. The biggest reason being that the name could change at any time, but I don't want old documents to become outdated. I still want them to be associated with one another.
>>>
>>
>> I'd suggest, if possible (and I know you already have a bunch of data, so maybe not for you, but for people coming along on new projects) to store your keywords on your docs and drop the "feature" that keywords can be renamed at any time.
>>
>> Chris
>>
>>> Thanks a million,
>>> Mike Keen
>>
>
Re: Relational-esque behavior in CouchDB
Posted by Mike Keen <mk...@visiture.com>.
Chris,
It's not a feature of our application. It's a consequence of dealing with the Google AdWords API.
Thanks anyway,
Mike
On Mar 1, 2010, at 11:55 AM, J Chris Anderson wrote:
>
> On Mar 1, 2010, at 7:41 AM, Mike Keen wrote:
>
>> Hey,
>>
>> I am managing a database that has hundreds of thousands of documents (so far), all containing a field called "keyword_id". I am not storing the "keyword_name" inside of each individual document for several reasons. The biggest reason being that the name could change at any time, but I don't want old documents to become outdated. I still want them to be associated with one another.
>>
>
> I'd suggest, if possible (and I know you already have a bunch of data, so maybe not for you, but for people coming along on new projects) to store your keywords on your docs and drop the "feature" that keywords can be renamed at any time.
>
> Chris
>
>> Thanks a million,
>> Mike Keen
>
Re: Relational-esque behavior in CouchDB
Posted by J Chris Anderson <jc...@gmail.com>.
On Mar 1, 2010, at 7:41 AM, Mike Keen wrote:
> Hey,
>
> I am managing a database that has hundreds of thousands of documents (so far), all containing a field called "keyword_id". I am not storing the "keyword_name" inside of each individual document for several reasons. The biggest reason being that the name could change at any time, but I don't want old documents to become outdated. I still want them to be associated with one another.
>
I'd suggest, if possible (and I know you already have a bunch of data, so maybe not for you, but for people coming along on new projects) to store your keywords on your docs and drop the "feature" that keywords can be renamed at any time.
Chris
> Thanks a million,
> Mike Keen