【发布时间】:2016-07-25 07:27:21
【问题描述】:
我有以下查询在 mongoDB 中工作,但在 PHP 中不工作。 MongoDB查询
db.energy_meter.aggregate(
{
$unwind: {
path:"$KeyValues",
includeArrayIndex:"arrayIndex",
preserveNullAndEmptyArrays:true
}
},
{
$project: {
timestamp:{
"$add":["$EventTS",{"$multiply":[60000,"$arrayIndex"]}]
} ,
"RPhaseVoltage":"$KeyValues.RPhaseVoltage",
arrayIndex:1,
}
}
);
以上查询转换为PHP
$cursor = DB::collection('energy_meter')->raw(function($collection)
{
return $collection->aggregate([
[
'$unwind' =>
['path' => '$KeyValues'],
['includeArrayIndex' => 'arrayIndex'],
['preserveNullAndEmptyArrays' => 'true']
],
[
'$project' =>
[
'timestamp' => [
'$add' => [
'$EventTS',
['$multiply' => [60000, '$arrayIndex']]
]
]
],
[
'MainsInputVoltagev' => ['$KeyValues.MainsInputVoltagev']
],
[
'arrayIndex' => 1
]
]
]);
});
我收到以下错误
RuntimeException in Aggregate.php line 168: A pipeline stage specification object must contain exactly one field.
转换后的 php 查询有什么问题?请提出上述问题的解决方案。
【问题讨论】:
标签: php mongodb laravel mongodb-query laravel-5.2