Skip to content

Instantly share code, notes, and snippets.

@addywaddy
Created October 13, 2008 23:32
Show Gist options
  • Save addywaddy/16627 to your computer and use it in GitHub Desktop.
Save addywaddy/16627 to your computer and use it in GitHub Desktop.
//map:
function(doc) {
if(doc.type == "document") {
emit(doc._id, doc);
}
else if(doc.type == "version") {
emit(doc.document_id, 1);
}
}
//reduce:
function(keys, values) {
var version_count = 0;
for(var i=0; i<values.length; i++) {
switch (typeof values[i]) {
case "number":
version_count += values[i];
case "object":
if (values[i]._id) {
result = values[i];
}
}
}
result.version_count = version_count;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment