Created
February 10, 2012 00:30
-
-
Save michaeltwofish/1784787 to your computer and use it in GitHub Desktop.
Lithium MongoDB map reduce example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$map = 'function() { | |
this.forms.forEach(function(form){ | |
form.clusters.forEach(function(cluster){ | |
cluster.items.forEach(function(item){ | |
emit(item, item); | |
}) | |
}) | |
}) | |
}'; | |
$reduce = 'function (key, values) { | |
return values; | |
}'; | |
// Run the command | |
$items = Test::connection()->connection->command(array( | |
'mapreduce' => 'tests', | |
'map' => $map, | |
'reduce' => $reduce, | |
'out' => array('inline' => 1) | |
)); | |
foreach ($items['results'] as $item) { | |
var_dump($item['value']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment