couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Woodward <>
Subject Re: Writing View to Get Unique Values in Arrays Across Documents
Date Sat, 22 Jan 2011 01:04:41 GMT
Very close on this so thanks again to everyone for their input.

Last issue I believe.

What I wound up with for my map function is this:
function(doc) {
  if ( != '' && doc.witnesses != '[]') {
    doc.witnesses.forEach(function(witness) {
      if (witness.firstName != '' && witness.lastName != '') {
        var wit = {};
        wit.firstName = witness.firstName;
        wit.lastName = witness.lastName;
        emit([, wit], null);

Throw in a reduce and ?group=true and that's working perfectly, outputting
things like:

Only thing I need to do now is be able to use start and end keys. Start key
is working fine, end key not so much for some reason.

In other instances where my key is an array and the second value is a string
(let's use a date string as an example), I do something like this:

That will give me all results with "Baz" in the first array element,
starting with 01/01/2011, and then all the rest of results for Baz
regardless of what the date is via the {} in the endkey.

In the case of this data, however, if I want to get back all witnesses for a
specific office this doesn't work:

That yields 0 rows. If I do this, it works in terms of *starting* with the
correct office, but I can't figure out the correct endkey to get it to only
show witnesses for that particular office:

Is this because the second element of my array key isn't a simple string?

Matthew Woodward / Twitter: @mpwoodward

Please do not send me proprietary file formats such as Word, PowerPoint,
etc. as attachments.

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