incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randall Leeds <randall.le...@gmail.com>
Subject Re: Writing View to Get Unique Values in Arrays Across Documents
Date Wed, 19 Jan 2011 23:49:45 GMT
Seems like you want to emit the idToRetrieveBy as the key from the map
function and the entire array as the value.
Reduce function can reduce many arrays to the de-duplicated superset.
I'd worry about hitting the reduce limit if you're expecting large arrays.

On Wed, Jan 19, 2011 at 15:22, Matthew Woodward <matt@mattwoodward.com> wrote:
> Been banging my head on this one only briefly but figured I'd ask before
> banging further.
>
> I have documents with a property that's an array. I want to write a view to
> retrieve all documents based on an ID in the document (not the document ID,
> but another ID that will exist in multiple documents), and the ultimate end
> result I want is the distinct/unique values from the array data across these
> documents.
>
> To give a concrete example, let's say I have the following two documents:
>
> DOCUMENT 1:
> idToRetrieveBy: 1
> arrayData: ['Homer','Marge','Bart']
>
> DOCUMENT 2:
> idToRetrieveBy: 1
> arrayData: ['Homer','Marge','Bart','Lisa','Maggie']
>
> From the view, what I'd want to get back is:
> ['Homer','Marge','Bart','Lisa','Maggie']
>
> Any ideas on how to go about that, or is that something I'd have to crunch
> on the application side of things?
>
> 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
View raw message