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''的每个标签返回? –