本文整理汇总了Golang中github.com/garyburd/go-mongo/mongo.Cursor.Close方法的典型用法代码示例。如果您正苦于以下问题:Golang Cursor.Close方法的具体用法?Golang Cursor.Close怎么用?Golang Cursor.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/garyburd/go-mongo/mongo.Cursor
的用法示例。
在下文中一共展示了Cursor.Close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: expectCount
// expectCount iterates through the cursor results and logs a fatal error if
// the number of documents is not equal to n.
func expectCount(cursor mongo.Cursor, n int) {
defer cursor.Close()
i := 0
for cursor.HasNext() {
i += 1
var m mongo.M
err := cursor.Next(&m)
if err != nil {
log.Fatal(err)
}
}
if i != n {
log.Fatalf("Got result count=%d, want %d", i, n)
}
}
示例2: expectFieldValues
// expectFieldValues iterates through the cursor and logs a fatal error if
// the a document does not have field in values or if a value in values was not
// found in a document.
func expectFieldValues(cursor mongo.Cursor, field string, values ...interface{}) {
defer cursor.Close()
found := map[interface{}]bool{}
for cursor.HasNext() {
var m mongo.M
err := cursor.Next(&m)
if err != nil {
log.Fatal(err)
}
found[m["name"]] = true
}
for _, value := range values {
if !found[value] {
log.Fatalf("Expected result %v not found\n", value)
} else {
delete(found, value)
}
}
for value, _ := range found {
log.Fatalf("Unexpected result %v found\n", value)
}
}