incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Woodward <m...@mattwoodward.com>
Subject Re: Writing View to Get Unique Values in Arrays Across Documents
Date Thu, 20 Jan 2011 06:21:58 GMT
On Wed, Jan 19, 2011 at 3:48 PM, Jan Lehnardt <jan@apache.org> wrote:

>
> http://guide.couchdb.org/editions/1/en/cookbook.html#unique


I'm sure I'm doing something wrong but for the life of me I can't get that
example to work. It seems to choke when I try to emit each item in the array
as a variable name in the forEach loop.

For example, this works but isn't what I want to output. Just tried this to
see if the forEach was working which based on the document count I get back
it seems to be.

{
   "byOffice": {
       "map": "function(doc) { if (doc.office != '' && doc.witnesses !=
'[]') { doc.witnesses.forEach(function(witness) { emit(doc.office, null);});
}}"
   }
}

So that outputs doc.office for each witness which isn't what I want, but as
I said based on the guesstimate of the rows returned compared to what I know
about the data that seems to be more or less accurate. So the loop is
working at least.

When I change to this, however, things fail:
{
   "byOffice": {
       "map": "function(doc) { if (doc.office != '' && doc.witnesses !=
'[]') { doc.witnesses.forEach(function(witness) { emit(witness, null);});
}}"
   }
}

In Firefox I get a blank white screen and view source is empty, but in
Chrome it shows this error detail:
Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error.

It doesn't seem like it'd be an issue with it returning too many documents
since the forEach works with other data (and returns ~12,000 rows), so my
guess is I'm missing a fundamental piece of how this all works. I'll be
added a reduce function once I get this piece working if that makes any
difference, because ultimately I want the unique values, but for now I'm
happy just seeing them all returned including dupes.

Thanks.

-- 
Matthew Woodward
matt@mattwoodward.com
http://blog.mattwoodward.com
identi.ca / Twitter: @mpwoodward

Please do not send me proprietary file formats such as Word, PowerPoint,
etc. as attachments.
http://www.gnu.org/philosophy/no-word-attachments.html

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message