我在让 Mongodb 聚合工作时遇到了一些困难。它一直给我null。请帮忙。下面是用php编写的代码。谢谢。
我想要做的是总结 2 个特定日期之间的 2 个字段的值,请求和响应
try {
$mongodb = new MongoClient("mongodb://ad:pass2word1@localhost");
$database = $mongodb->selectDB('backend');
$collection = new MongoCollection($database, 'RequestSummary');
$pipeline = array(
array(
'$group' => array(
'_id' => array(
'request' => array('$sum' => '$Requests'),
'response' => array('$sum' => '$Responses')
)
)
),
array(
'$match' => array(
'RequestDate' => array(
'$gte' => intval($_SESSION['range_from']),
'$lte' => intval($_SESSION['range_to'])
)
)
)
);
$collection->aggregate($pipeline);
var_dump($g);
} catch (MongoConnectionException $exc) {
echo $exc->getTraceAsString();
}