在 setLimit() 方法中,我应该保留什么来获取数据中的所有记录
包 - 使用:go.mongodb.org/mongo-driver/bson
go.mongodb.org/mongo-driver/mongo
go.mongodb.org/mongo-driver/mongo/options
findOption := options.Find()
findOption.SetLimit(?)
var res1 []Person
cur, err := collection.Find(context.TODO(), bson.D{}, findOption)
if err != nil {
log.Fatal(err)
}
for cur.Next(context.TODO()) {
var elem Person
err := cur.Decode(&elem)
if err != nil {
log.Fatal(err)
}
res1 = append(res1, elem)
}
if err := cur.Err(); err != nil {
log.Fatal(err)
}
// Close the cursor once finished
cur.Close(context.TODO())
fmt.Printf("Found multiple documents (array of pointers): %+v\n", res1)
蝴蝶刀刀
相关分类