From 3a826ac216f5ed60062cd8aca0ae1707c297f330 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Wed, 7 Dec 2022 15:16:09 +0100 Subject: [PATCH] fixed sort via pipeline --- crud.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crud.go b/crud.go index 6946e89..a307963 100644 --- a/crud.go +++ b/crud.go @@ -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)