Skip to content

Instantly share code, notes, and snippets.

@beathyate
Created March 3, 2010 14:09
Show Gist options
  • Save beathyate/320625 to your computer and use it in GitHub Desktop.
Save beathyate/320625 to your computer and use it in GitHub Desktop.
map = "function() { emit(this.cargo, {weight: this.weight}); }"
reduce = <<-FUNC
function(key, values) {
var weight = 0;
values.forEach(function(doc) {
weight += doc.weight
});
return({weight: weight});
};
FUNC
Shipments.collection.map_reduce(map, reduce, ).find.sort("value.weight").to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment