Skip to content

Instantly share code, notes, and snippets.

@michaeltwofish
Forked from ringmaster/gist:1777673
Created February 9, 2012 05:53
Show Gist options
  • Save michaeltwofish/1777704 to your computer and use it in GitHub Desktop.
Save michaeltwofish/1777704 to your computer and use it in GitHub Desktop.
Get all items from a test
db.tests.remove({slug: "foo"})
db.tests.insert({slug: "foo", forms: [ {slug: "section 1", clusters: [
{slug: "cluster 1", items: [1,2,3]},
{slug: "cluster 2", items: [4,5,6]}
]}]});
var map = function() {
this.forms.forEach(function(form){
form.clusters.forEach(function(cluster){
cluster.items.forEach(function(item){
emit(item, item);
})
})
})
};
var reduce = function (key, values) {
return values;
}
db.tests.mapReduce(map, reduce, {query: {slug: "foo"}, out: {inline: 1} });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment