Skip to content

Commit 3fca9df

Browse files
committed
改进mongo的order方法
1 parent 715e55d commit 3fca9df

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/db/Mongo.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,9 @@ public function limit(int $offset, ?int $length = null)
486486
public function order($field, string $order = '')
487487
{
488488
if (is_array($field)) {
489-
$this->options['sort'] = $field;
489+
$this->options['sort'] = array_map(function ($val) {
490+
return 'asc' == strtolower($val) ? 1 : -1;
491+
}, $field);
490492
} else {
491493
$this->options['sort'][$field] = 'asc' == strtolower($order) ? 1 : -1;
492494
}

0 commit comments

Comments
 (0)