使用 php 在 mongodb 中执行聚合时执行命令时出现未知错误(返回空文档)


Unknown error executing command (empty document returned), when executing aggregate in mongodb using php

我想在mongodb中分组:我的代码如下:

$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);

但是错误发生了:

类型:蒙戈结果异常

消息:执行命令时出现未知错误(空文档) 返回)

文件名: D:''Projects''sns''grl1.0''trunk''src''server''GRL''application''models''user_model.php

行号:195

我该如何解决这个问题。请帮帮我!!

问题是php版本。总而言之,php 版本将超过 5.6.1我认为您的 php 版本可能低于 5.6。请使用 xampp 更高版本。