當前位置: 首頁>>代碼示例>>Golang>>正文


Golang mgo.Query類代碼示例

本文整理匯總了Golang中labix/org/v2/mgo.Query的典型用法代碼示例。如果您正苦於以下問題:Golang Query類的具體用法?Golang Query怎麽用?Golang Query使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Query類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
開發者ID:rogpeppe,項目名稱:charmstore,代碼行數:31,代碼來源:store.go

示例2: refresh

func (e *Environment) refresh(query *mgo.Query) error {
	err := query.One(&e.doc)
	if err == mgo.ErrNotFound {
		return errors.NotFoundf("environment")
	}
	return err
}
開發者ID:jimmiebtlr,項目名稱:juju,代碼行數:7,代碼來源:environ.go

示例3: NewPagination

// 創建一個分頁結構體
func NewPagination(query *mgo.Query, url string, prePage int) *Pagination {
	p := Pagination{}
	p.query = query
	p.count, _ = query.Count()
	p.prePage = prePage
	return &p
}
開發者ID:EPICPaaS,項目名稱:MessageBlog,代碼行數:8,代碼來源:Pagination.go

示例4: usergroupSort

func usergroupSort(q *mgo.Query, sortFields []string) {
	if len(sortFields) > 0 {
		q.Sort(sortFields...)
		return
	}

	q.Sort("-_id")
}
開發者ID:qiandashuai,項目名稱:xuanwu,代碼行數:8,代碼來源:gen_usergroup.go

示例5: CatTree

func (ctx *DBCtx) CatTree(root bson.ObjectId) []Catergory {
	all := []Catergory{}
	var query *mgo.Query

	if root.Valid() {
		query = ctx.catColl.Find(bson.M{"ancestors": root})
	} else {
		query = ctx.catColl.Find(bson.M{"parent": bson.M{"$exists": false}})
	}
	query.All(&all)

	return all
}
開發者ID:openvn,項目名稱:gocms,代碼行數:13,代碼來源:dbctx.go

示例6: Do

func (qw *QueryWork) Do(c chan<- interface{}) {
	customerID := qw.randSource.Int31n(MaxNumCustomers)
	cashRegisterID := qw.randSource.Int31n(MaxNumCashRegisters)
	price := qw.randSource.Float64()*MaxPrice + float64(customerID)/100.0
	// generate a random time since qw.StartTime
	// there is likely a better way to do this
	since := time.Since(qw.startTime)
	sinceInNano := since.Nanoseconds()
	var randomTime int64
	if sinceInNano > 0 {
		randomTime = qw.randSource.Int63n(sinceInNano)
	}
	timeToQuery := qw.startTime.Add(time.Duration(randomTime))

	var query *mgo.Query
	if qw.numQueriesSoFar%3 == 0 {
		filter := bson.M{"$or": []bson.M{
			bson.M{"pr": price, "ts": timeToQuery, "cid": bson.M{"$gte": customerID}},
			bson.M{"pr": price, "ts": bson.M{"$gt": timeToQuery}},
			bson.M{"pr": bson.M{"$gt": price}}}}
		projection := bson.M{"pr": 1, "ts": 1, "cid": 1}
		query = qw.coll.Find(filter).Select(projection).Hint("pr", "ts", "cid")
	} else if qw.numQueriesSoFar%3 == 1 {
		filter := bson.M{"$or": []bson.M{
			bson.M{"crid": cashRegisterID, "pr": price, "cid": bson.M{"$gte": customerID}},
			bson.M{"crid": cashRegisterID, "pr": bson.M{"$gt": price}},
			bson.M{"crid": bson.M{"$gt": cashRegisterID}}}}
		projection := bson.M{"crid": 1, "pr": 1, "cid": 1}
		query = qw.coll.Find(filter).Select(projection).Hint("crid", "pr", "cid")
	} else {
		filter := bson.M{"$or": []bson.M{
			bson.M{"pr": price, "cid": bson.M{"$gte": customerID}},
			bson.M{"pr": bson.M{"$gt": price}}}}
		projection := bson.M{"pr": 1, "cid": 1}
		query = qw.coll.Find(filter).Select(projection).Hint("pr", "cid")
	}

	var result bson.M
	iter := query.Limit(*queryResultLimit).Iter()
	for iter.Next(&result) {
	}
	qw.numQueriesSoFar++
	c <- Result{NumQueries: 1}
}
開發者ID:Tokutek,項目名稱:go-benchmark,代碼行數:44,代碼來源:iibench.go


注:本文中的labix/org/v2/mgo.Query類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。