本文整理匯總了Golang中labix/org/v2/mgo.Query.Limit方法的典型用法代碼示例。如果您正苦於以下問題:Golang Query.Limit方法的具體用法?Golang Query.Limit怎麽用?Golang Query.Limit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類labix/org/v2/mgo.Query
的用法示例。
在下文中一共展示了Query.Limit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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}
}