1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| db.getCollection("events").aggregate(
[
{
"$match" : {
"properties.device.id_device" : "1"
}
},
{
"$group" : {
"_id" : {
"properties᎐device᎐id_device" : "$properties.device.id_device",
"properties᎐device᎐name" : "$properties.device.name",
"properties᎐data᎐DAY" : "$properties.data.DAY"
},
"AVG(properties᎐data᎐T)" : {
"$avg" : "$properties.data.T"
}
}
},
{
"$project" : {
"properties.device.id_device" : "$_id.properties᎐device᎐id_device",
"properties.device.name" : "$_id.properties᎐device᎐name",
"properties.data.DAY" : "$_id.properties᎐data᎐DAY",
"AVG(properties᎐data᎐T)" : "$AVG(properties᎐data᎐T)",
"_id" : NumberInt(0)
}
}
],
{
"allowDiskUse" : true
}
);
Comment dois-je placer cette agrégation dans mon code PHP ? (cf. ci-dessous)
<?php
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$filter = ['properties.farm.id_farm'=>1];
$options = [
'projection' => ['_id' => 0],
'sort' => ['x' => -1],
];
$query = new MongoDB\Driver\Query($filter, $options);
$cursor = $manager->executeQuery('digilab.parcels', $query);
var_dump($cursor);
?> |
Partager