diff --git a/mongo/collection.go b/mongo/collection.go index 369e6babee58a861cd60a1a00018456445680e97..cbf723697844a6340060bb529aa4da51a849a5e5 100644 --- a/mongo/collection.go +++ b/mongo/collection.go @@ -289,11 +289,13 @@ func (self *SourceCollection) buildQuery(terms ...interface{}) *mgo.Query { var delim = struct { Limit int Offset int + Fields *db.Fields Sort *db.Sort }{ -1, -1, nil, + nil, } // Conditions @@ -301,6 +303,8 @@ func (self *SourceCollection) buildQuery(terms ...interface{}) *mgo.Query { for i, _ := range terms { switch t := terms[i].(type) { + case db.Fields: + delim.Fields = &t case db.Limit: delim.Limit = int(t) case db.Offset: @@ -322,7 +326,16 @@ func (self *SourceCollection) buildQuery(terms ...interface{}) *mgo.Query { res = res.Limit(delim.Limit) } - // Sorting result + // Delimiting fields. + if delim.Fields != nil { + sel := bson.M{} + for _, field := range *delim.Fields { + sel[field] = true + } + res = res.Select(sel) + } + + // Sorting result. if delim.Sort != nil { for key, val := range *delim.Sort { sval := to.String(val)