Skip to content

Commit

Permalink
修复 GetAllWithFields
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue authored Jul 18, 2024
1 parent 6f6e137 commit 6026dec
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,11 @@ func (s *Mgo) GetAllWithFields(results any, where map[string]any, _sort map[stri
opts := options.Find()
opts.SetSort(_sort)
if len(fields) > 0 {
var projection = make(bson.M, 0)
for _, s2 := range fields {
opts.SetProjection(bson.M{s2: 1})
projection[s2] = 1
}
opts.SetProjection(projection)
}
ctx := context.Background()
cur, err := s.GetCollection().Find(ctx, where, opts)
Expand Down

0 comments on commit 6026dec

Please sign in to comment.