本文整理汇总了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")
}