Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do the SQL equivalent of "DISTINCT" in CouchDB?

Tags:

couchdb

I have a bunch of MP3 metadata in CouchDB. I want to return every album that is in the MP3 metadata, but no duplicates.

A typical document looks like this:

{
   "_id": "005e16a055ba78589695c583fbcdf7e26064df98",
   "_rev": "2-87aa12c52ee0a406084b09eca6116804",
   "name": "Fifty-Fifty Clown",
   "number": 15,
   "artist": "Cocteau Twins",
   "bitrate": 320,
   "album": "Stars and Topsoil: A Collection (1982-1990)",
   "path": "Cocteau Twins/Stars and Topsoil: A Collection (1982-1990)/15 - Fifty-Fifty Clown.mp3",
   "year": 0,
   "genre": "Shoegaze"
}
like image 766
Blaine Lafreniere Avatar asked Mar 28 '10 20:03

Blaine Lafreniere


2 Answers

I believe your map/reduce would look something like:

function map(doc) {
    emit(doc.album, null);
}

function reduce(key, values) {
    return null;
}

Remember to query with the extra parameter group=true

like image 54
David Wolever Avatar answered Nov 09 '22 12:11

David Wolever


Have a look at View Cookbook for SQL Jockeys' Get Unique Values section.

like image 44
Adriaan Stander Avatar answered Nov 09 '22 12:11

Adriaan Stander