1
MongoDB中執行聚集時,我想組在MongoDB中:我下面的代碼:未知錯誤執行命令(空文件返回),使用PHP
$m = new MongoClient("localhost");
$c = $m->selectDB("grl_db")->selectCollection("USER_TBL");
$data = array (
'title' => 'this is my title',
'author' => 'bob',
'posted' => new MongoDate,
'pageViews' => 5,
'tags' => array ('fun', 'good', 'fun'),
'comments' => array (
array (
'author' => 'joe',
'text' => 'this is cool',
),
array (
'author' => 'sam',
'text' => 'this is bad',
),
),
'other' =>array (
'foo' => 5,
),
);
$d = $c->insert($data, array("w" => 1));
$ops = array(
array(
'$project' => array(
"author" => 1,
"tags" => 1,
)
),
array('$unwind' => '$tags'),
array(
'$group' => array(
"_id" => array("tags" => '$tags'),
"authors" => array('$addToSet' => '$author'),
),
),
);
$results = $c->aggregate($ops);
但犯錯時:
類型:MongoResultException
消息:未知錯誤執行命令(空文檔 返回)
文件名: d:\項目\ SNS \ grl1.0 \行李箱的\ src \服務器\ GRL \程序\型號\ user_model.php
行號:195
我怎麼能解決這個問題。請幫幫我!!!
你似乎想要的「作者」字段也在它自己的''註釋「數組中。那麼你期望看到什麼?你真的希望兩個作者都爲''fun''和''good''的每個標籤返回? –