我有一個問題,我需要一些幫助,但我覺得我很接近。它涉及鋰和MongoDB的代碼如下所示: http://pastium.org/view/0403d3e4f560e3f790b32053c71d0f2b地圖減少以獲得最受歡迎的標籤
$db = PopularTags::connection();
$map = new \MongoCode("function() {
if (!this.saved_terms) {
return;
}
for (index in this.saved_terms) {
emit(this.saved_terms[index], 1);
}
}");
$reduce = new \MongoCode("function(previous, current) {
var count = 0;
for (index in current) {
count += current[index];
}
return count;
}");
$metrics = $db->connection->command(array(
'mapreduce' => 'users',
'map' => $map,
'reduce' => $reduce,
'out' => 'terms'
));
$cursor = $db->connection->selectCollection($metrics['result'])->find()->limit(1);
print_r($cursor);
/**
User Data In Mongo
{
"_id" : ObjectId("4e789f954c734cc95b000012"),
"email" : "[email protected]",
"saved_terms" : [
null,
[
"technology",
" apple",
" iphone"
],
[
"apple",
" water",
" beryy"
]
] }
**/
我有一個用戶節約方面,他們搜索,然後我試圖讓最populars條款 但我不斷收到這樣的錯誤:未捕獲的異常'異常'與消息'MongoDB :: __構造(無效名稱)。有沒有人有任何想法如何做到這一點或某些方向?