fixed sort via pipeline
This commit is contained in:
parent
ede07bb49a
commit
3a826ac216
8
crud.go
8
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)
|
||||
|
Loading…
Reference in New Issue
Block a user