慕尼黑5688855
2022-05-18 14:26:01
在 setLimit() 方法中,我應(yīng)該保留什么來獲取數(shù)據(jù)中的所有記錄包 - 使用:go.mongodb.org/mongo-driver/bsongo.mongodb.org/mongo-driver/mongogo.mongodb.org/mongo-driver/mongo/optionsfindOption := options.Find()findOption.SetLimit(?)var res1 []Personcur, 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 finishedcur.Close(context.TODO())fmt.Printf("Found multiple documents (array of pointers): %+v\n", res1)
1 回答

蝴蝶刀刀
TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超8個(gè)贊
FindOptions.SetLimit()
如果您不想限制結(jié)果的數(shù)量,最簡單的方法是不調(diào)用。如果你沒有通過FindOptions
,或者你通過了一個(gè)你沒有設(shè)置限制的地方,默認(rèn)情況下,結(jié)果是不受限制的。
如果您有一個(gè)FindOptions
先前已設(shè)置限制的值,您可以設(shè)置一個(gè)限制0
以“撤消”限制。
// The maximum number of documents to return. The default value is 0, which means that all documents matching the
// filter will be returned. A negative limit specifies that the resulting documents should be returned in a single
// batch. The default value is 0.
Limit *int64
- 1 回答
- 0 關(guān)注
- 467 瀏覽
添加回答
舉報(bào)
0/150
提交
取消