我正在尝试使用官方 PHP 驱动程序和组(http://www.php.net/manual/en/mongocollection.group.php)函数将工作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));
和:print_r()
_$result
Array
(
[retval] => Array
(
)
[count] => 0
[keys] => 0
[ok] => 1
)
谢谢!