couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Lehnardt <...@apache.org>
Subject Re: Writing View to Get Unique Values in Arrays Across Documents
Date Wed, 19 Jan 2011 23:48:31 GMT
Hi Matthew,

On 20 Jan 2011, at 00:22, Matthew Woodward 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.

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

Cheers
Jan
-- 


> 
> 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