2016-03-07 107 views
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

我怎么能解决这个问题。请帮帮我!!!

+0

你似乎想要的“作者”字段也在它自己的''注释“数组中。那么你期望看到什么?你真的希望两个作者都为''fun''和''good''的每个标签返回? –

回答

0

问题是php版本。 要汇总,PHP版本将超过5.6.1 我认为你的PHP版本可能低于5.6。 请使用xampp更高的版本。

+0

感谢您的关注。我尝试过,但发生相同的错误, –