I'm using PHP with the MongoDb DRIVER.
I can use simple query using sorts
, selecting a record by id, but I want to make a query that takes the last records of the collection, grouped by idHostName
.
In the document I have the AliveBees
Collection with the fields (_id,_idHostName,CollectDates)
In MongoDB the query works:
db.AliveBees.aggregate(
[
{ $sort: { CollectDate: 1, _idHostName: 1 } },
{
$group:
{
_id: "$_idHostName",
"_idHostName": {"$last":"$_idHostName"},
lastCollectDate: { $last: "$CollectDate" }
}
}
]
)
But in PHP I can not mount it to return this data to me.