fixed sort via pipeline

This commit is contained in:
Sebastian Frank 2022-12-07 15:16:09 +01:00
parent ede07bb49a
commit 3a826ac216

View File

@ -176,13 +176,15 @@ func (db *MgoDatabase) ReadCollection(results interface{}, filter bson.M, select
} }
if len(sort) > 0 { if len(sort) > 0 {
sortM := bson.M{} sortM := bson.D{}
for _, s := range sort { for _, s := range sort {
if strings.HasPrefix(s, "-") { if strings.HasPrefix(s, "-") {
s = s[1:] s = s[1:]
sortM[s] = -1 sortM = append(sortM, bson.DocElem{Name: s, Value: -1})
// sortM[s] = -1
} else { } else {
sortM[s] = 1 sortM = append(sortM, bson.DocElem{Name: s, Value: 1})
// sortM[s] = 1
} }
} }
// spew.Dump(sortM) // spew.Dump(sortM)