Skip to content

Commit

Permalink
Use file index in the specified order
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed May 20, 2024
1 parent 86d94c5 commit 3840dc5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/GridFS/GridFSAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '/']]]];
Expand All @@ -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'],
]];
Expand Down

0 comments on commit 3840dc5

Please sign in to comment.