How to sort by desc [fillter][date] in mongoDB php
My code:
<?php
require_once __DIR__ . '/vendor/autoload.php' ;
$collection = (new MongoDB\Client)->API->PNR;
$cursor = $collection->find();
$i=0;
foreach ($cursor as $item) {
$i=$i 1;
$number=$item["data"]["data"]["number"];
$reservationDate=$item["data"]["data"]["reservationDate"];
$bookingTimeLimit=$item["data"]["data"]["bookingTimeLimit"];
?>
CodePudding user response:
Use this which is similar to mql
$cursor = $collection->find([], [
'sort' => ['fillter.date' => -1]
]);
foreach ($cursor as $item) {
//process collections
}