本文整理匯總了Golang中labix/org/v2/mgo.Query.Sort方法的典型用法代碼示例。如果您正苦於以下問題:Golang Query.Sort方法的具體用法?Golang Query.Sort怎麽用?Golang Query.Sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類labix/org/v2/mgo.Query
的用法示例。
在下文中一共展示了Query.Sort方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CharmEvent
// CharmEvent returns the most recent event associated with url
// and digest. If the specified event isn't found the error
// ErrUnknownChange will be returned. If digest is empty, any
// digest will match.
func (s *Store) CharmEvent(url *charm.URL, digest string) (*CharmEvent, error) {
// TODO: It'd actually make sense to find the charm event after the
// revision id, but since we don't care about that now, just make sure
// we don't write bad code.
if err := mustLackRevision("CharmEvent", url); err != nil {
return nil, err
}
session := s.session.Copy()
defer session.Close()
events := session.Events()
event := &CharmEvent{Digest: digest}
var query *mgo.Query
if digest == "" {
query = events.Find(bson.D{{"urls", url}})
} else {
query = events.Find(bson.D{{"urls", url}, {"digest", digest}})
}
err := query.Sort("-time").One(&event)
if err == mgo.ErrNotFound {
return nil, ErrNotFound
}
if err != nil {
return nil, err
}
return event, nil
}
示例2: usergroupSort
func usergroupSort(q *mgo.Query, sortFields []string) {
if len(sortFields) > 0 {
q.Sort(sortFields...)
return
}
q.Sort("-_id")
}