couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <>
Subject Re: Adding attributes to a document in the view?
Date Thu, 18 Dec 2008 16:46:18 GMT
On Thu, Dec 18, 2008 at 8:41 AM, Daniel DeLeo <> wrote:
> Is it possible in the newer versions to add attributes to a document object
> in the view?  For example, on 0.8.0, if your view map function is:
> function(doc) {
>  doc.computed_attribute = 'hello, world';
>  emit(doc._id, doc);
> };
> The view gives a 50X error, and a stack trace in futon.  Is it possible to
> do this in any version of Couch?

It is not recommended. You may be able to get away with it on new
versions of CouchDB (as Spidermonkey's freeze seems to have stopped
working for us).

A better solution would be:

function(doc) {
  var value = {
    computed_attribute : 'hello, world',
    another : doc.another
  emit(doc._id, value)

This avoids the pitfall of changes to the doc leaking into unrelated
map function calls elsewhere in the design document.

Chris Anderson

View raw message