Skip to content

Instantly share code, notes, and snippets.

@iamwilhelm
Created May 30, 2009 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamwilhelm/120523 to your computer and use it in GitHub Desktop.
Save iamwilhelm/120523 to your computer and use it in GitHub Desktop.
how to get all the attributes names of records in couchdb
/* 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