Created
May 30, 2009 14:56
-
-
Save iamwilhelm/120523 to your computer and use it in GitHub Desktop.
how to get all the attributes names of records in couchdb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* this mapreduce pair returns all the keys of the attribute hash from all records in the system */ | |
/* the map function to return all the values of keys */ | |
function(doc) { | |
keys = {} | |
for(key in doc) { | |
if (key != "_id" && key != "_rev") { | |
keys[key] = 1 | |
} | |
} | |
emit(null, keys); | |
} | |
/* the reduce function to combine all the keys of the attribute hash in the values */ | |
function(keys, values, rereduce) { | |
result = {} | |
for(hash_name in values) { | |
hash = values[hash_name]; | |
// merge all the hashes together | |
for(key in hash) { | |
result[key] = hash[key]; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment