fixed sort via pipeline

This commit is contained in:
Sebastian Frank 2022-12-07 15:16:09 +01:00
parent ede07bb49a
commit 3a826ac216
1 changed files with 5 additions and 3 deletions

View File

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