[GODRIVER-1786] limit 无效 Created: 10/Nov/20  Updated: 27/Oct/23  Resolved: 18/Nov/20

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: 1.4.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: 建立 梁 Assignee: Kevin Albertson
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Lark20201110170014.png    

 Description   

在查询过程中设置了findoptions.limit,但是查出来的文档是全部.



 Comments   
Comment by Kevin Albertson [ 18/Nov/20 ]

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.

Comment by 建立 梁 [ 10/Nov/20 ]

问题已解决

Generated at Thu Feb 08 08:37:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.