4
我有這個疑問從mysql的 MongoDB的轉換爲使用PHPPHP MongoDB的例外:流水線級規範對象必須包含一個字段
select content_id ,member_id, content_type_id,social_network_id from recent_activty where content_type_id = 10 AND social_network_id = 9 order by id desc group by content_id limit 5
我需要像結果:
array(2) {
["content_id"]=>
string(6) "122558"
["member_id"]=>
string(6) "180306",
["content_type_id"]=>
string(6) "10",
["social_network_id"]=>
string(6) "9",
},
array(2) {
["content_id"]=>
string(6) "122549"
["member_id"]=>
string(6) "180306",
["content_type_id"]=>
string(6) "10",
["social_network_id"]=>
string(6) "9",
},
array(2) {
["content_id"]=>
string(6) "122528"
["member_id"]=>
string(6) "180306",
["content_type_id"]=>
string(6) "10",
["social_network_id"]=>
string(6) "9",
},
我試過Aggregation Framework爲
$result = $collection->aggregate(array(
'$match' => array('content_type_id'=>"10", "social_network_id"=>"9"),
'$project' => array('content_type_id'=>1, "social_network_id"=>1, "content_id"=>1),
'$group' => array('_id' => array('member_id'=>'$member_id')),
'$sort' => array('_id'=>-1),
'$limit' => 5,
));
但我得到這個錯誤
["errmsg"]=>
string(80) "exception: A pipeline stage specification object must contain exactly one field."
,我試圖
$result = $collection->aggregate(array(
'$match' => array('content_type_id'=>"10", "social_network_id"=>"9"),
'$project' => array("_id"=>'$content_id' ,'content_type_id'=>1),
'$group' => array('_id' => array('content_id'=>'$content_id', 'member_id'=>'$member_id')),
)
);
我是新來的MongoDB和我花了很多時間來此查詢轉換,解決這個錯誤,任何一個可以幫我
感謝
$ group,您需要''_id'=>'$ content_id'' – Sammaye
對不起,同樣的錯誤仍然存在 –