Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created October 15, 2012 20:29
Show Gist options
  • Select an option

  • Save makevoid/3895205 to your computer and use it in GitHub Desktop.

Select an option

Save makevoid/3895205 to your computer and use it in GitHub Desktop.
map reduce mongoid
map = %Q{
function() {
emit(this.name, { deployments: this.deployments })
}
}
reduce = %Q{
function(key, values) {
var result = {}
values.forEach(function(value) {
result.deployments_succeded = false
values.deployments.forEach(function(deployment) {
if (deployment.successful)
result.deployments_succeeded = true
})
})
return result
}
}
# App.collection.map_reduce(map, reduce, {out: {merge: "name"}})
# App.collection.map_reduce(map, reduce, {out: {inline: true}, raw: true})
# http://mongoid.org/en/mongoid/docs/querying.html#map_reduce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment