From 3840dc56fcb3b9e9b297fe2a78a094d1d9fe56ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 20 May 2024 17:43:45 +0200 Subject: [PATCH] Use file index in the specified order --- src/GridFS/GridFSAdapter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GridFS/GridFSAdapter.php b/src/GridFS/GridFSAdapter.php index 2409a4c5c..50cd3c65c 100644 --- a/src/GridFS/GridFSAdapter.php +++ b/src/GridFS/GridFSAdapter.php @@ -289,7 +289,7 @@ public function listContents(string $path, bool $deep): iterable $pipeline[] = ['$match' => ['filename' => new Regex('^' . preg_quote($path))]]; } // Get the last revision of each file - $pipeline[] = ['$sort' => ['filename' => 1, 'uploadDate' => -1]]; + $pipeline[] = ['$sort' => ['filename' => 1, 'uploadDate' => 1]]; if ($deep === false) { $pipeline[] = ['$addFields' => ['splitpath' => ['$split' => ['$filename', '/']]]]; @@ -300,7 +300,7 @@ public function listContents(string $path, bool $deep): iterable 'isDir' => ['$ne' => [['$size' => '$splitpath'], $pathdeep + 1]], ], // Get the metadata of the last revision of each file - 'file' => ['$first' => '$$ROOT'], + 'file' => ['$last' => '$$ROOT'], // The "lastModified" date is the date of the last uploaded file in the directory 'uploadDate' => ['$max' => '$uploadDate'], ]];