couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christopher O'Connell" <jwritec...@gmail.com>
Subject Re: Writing View to Get Unique Values in Arrays Across Documents
Date Fri, 21 Jan 2011 23:39:23 GMT
Let me see if I understand you:

In one document you've got

wittnesses: [ ...
   {
   first: Bob,
   last: Smith,
   testimony: Suspect Did It
   }
],

In another document you've got

wittnesses: [ ...
   {
   first: Bob,
   last: Smith,
   testimony: Suspect is as innocent as my grandmother
   }
],

What you'd like is that the object { first: Bob, last: Smith } only appears
once in the output, even though his testimony differs?

In that case, simply limit the fields which you emit:

function(map) {
   // Generate Keys[] in some fashion
   map.wittnesses.forEach(function(element)) {
     var per = {};
     per.firstName = element.firstName;
     per.lastName = element.lastName;
     emit(Keys,per);
   }
}

This will create a map in which you emit simplified person documents with
just first and last name. Indeed, depending on your display requirements,
you might even go ahead and concatenate first + last into a single string in
the mapper.

~ Christopher
On Fri, Jan 21, 2011 at 15:16, Matthew Woodward <matt@mattwoodward.com>wrote:

> On Wed, Jan 19, 2011 at 11:32 PM, Nils Breunese <N.Breunese@vpro.nl>
> wrote:
>
> > I suggest checking the log file to get the actual error message or using
> an
> > HTTP tool which will show you the error message properly (curl for
> instance)
>
>
> Thanks--got sidetracked on this task the last couple of days but will
> definitely do that.
>
> Another wrinkle to this that may cause me to have to go another way anyway.
>
> The data within the array that I want to get distinct values for looks like
> this:
> {"firstName":"Bob","lastName":"Smith","testimony":"Some long string of
> text"}
>
> So I may have several of those within the array.
>
> The issue is, and I didn't think about this until I got the chance to take
> another run at this issue today, I'd like to get back unique values of just
> firstName and lastName across documents but not include the testimony field
> in considering whether or not the value is unique. In other words I don't
> want Bob Smith to come up as unique across documents simply because his
> testimony in one document differs from that in another document.
>
> Is that possible or do I need to rethink my document structure to better
> handle this type of data?
> --
> 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