fix(core): default to _id descending sort when sort is nil or parsing fails

Ensure MustGetSortOption returns a default bson.D{{"_id", -1}} on parse errors and
GetPaginationPipeline uses {_id: -1} when sort is nil to provide consistent default ordering.
This commit is contained in:
Marvin Zhang
2025-10-28 11:55:00 +08:00
parent 851097dc59
commit bd99899182
2 changed files with 5 additions and 1 deletions

View File

@@ -491,6 +491,9 @@ func GetPaginationPipeline(query bson.M, sort bson.D, skip, limit int) []bson.D
if query == nil {
query = bson.M{}
}
if sort == nil {
sort = bson.D{{"_id", -1}}
}
return []bson.D{
{{Key: "$match", Value: query}},
{{Key: "$sort", Value: sort}},