Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP驱动程序的MongoDB组查询_Php_Mongodb_Group By - Fatal编程技术网

使用PHP驱动程序的MongoDB组查询

使用PHP驱动程序的MongoDB组查询,php,mongodb,group-by,Php,Mongodb,Group By,我正在尝试使用官方PHP驱动程序和group()函数将工作的MongoDB组查询转换为PHP等效查询 以下是正在工作的原始MongoDB查询: db.collection.group( { keyf: function(doc) { var date = new Date(doc.executed); var dateKey = (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFul

我正在尝试使用官方PHP驱动程序和group()函数将工作的
MongoDB
组查询转换为
PHP
等效查询

以下是正在工作的原始MongoDB查询:

db.collection.group(
{
    keyf: function(doc) {
        var date = new Date(doc.executed);
        var dateKey = (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();
        return {'day': dateKey};
     },
    cond: { executed: { $gt: new Date('01/01/2013') }},
    initial: { executions:0 },
    reduce: function(obj, prev) { prev.executions++; }
});
这是我的不工作的PHP代码:

$keyf = new MongoCode('function(doc) {
    var date = new Date(doc.executed);
    var dateKey = (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();
    return {\'day\': dateKey};
}');

$initial = array("executions" => 0);
$reduce = "function(obj, prev) { prev.executions++; }";
$conditionals = array("executed" => array('$gt' => "new Date('01/01/2013')"));

$result = $c->group($keyf, $initial, $reduce, array("condition" => $conditionals));
以及
$result
print\u r()

Array
(
    [retval] => Array
        (
        )

    [count] => 0
    [keys] => 0
    [ok] => 1
)

谢谢

您的
条件
是比较字符串而不是日期。你需要一个新的。比如:

$cond_date = new MongoDate(strtotime("2013-01-01 00:00:00"));
$conditionals = array("executed" => array('$gt' => $cond_date));

完美的无论如何,我可以反转排序,而不是返回
1/30/2013
1/1/2013
,我希望
1/1/2013
1/30/2013
。谢谢