|
Hello a624669980@126.com, thank you for the report!
If I understand the screenshot, you were experiencing what appeared to be four results returned from the created cursor when you supplied a limit of two? I cannot reproduce this with a simple test:
client, err := mongo.Connect(ctx, opts)
|
if err != nil {
|
log.Fatal(err)
|
}
|
|
collection := client.Database("test").Collection("GODRIVER_1786")
|
filter := bson.D{{}}
|
cursor, _ := collection.Find(context.TODO(), filter, options.Find().SetLimit(2))
|
|
var resultArray []MyResult
|
defer cursor.Close(context.Background())
|
for cursor.Next(context.Background()) {
|
var myResult MyResult
|
if err := cursor.Decode(&myResult); err != nil {
|
log.Fatal(err)
|
}
|
resultArray = append(resultArray, myResult)
|
}
|
|
fmt.Println(len(resultArray), resultArray)
|
In my test, the collection "test.GODRIVER_1786" contains four documents, but indeed only two are returned.
Your comment translates to "Problem solved", so I am closing this. Please comment again with additional information (what version of the Go driver you are using and steps to reproduce) if you are still having an issue.
|