[GODRIVER-956] Legacy Find is not respecting limit Created: 11/Apr/19  Updated: 28/Oct/23  Resolved: 15/Apr/19

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: 1.0.0
Fix Version/s: 1.0.1

Type: Bug Priority: Major - P3
Reporter: Jeremy Loy Assignee: Isabella Siu (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Wire Protocol 3.2 (Azure CosmosDB)


Issue Links:
Backports
backported by GODRIVER-965 Backports "Legacy Find is not respect... Closed

 Description   

STR:
 The client should be connecting to a mongo instance such that

 top.SelectServer.Description.WireVersion.Max < 4

Create and execute a query that specifies limit.

Observe that a multiple of batchSize documents are returned, not the value of limit.

 * if limit < batchSize, batchSize is returned

 * if limit >= batchSize, n * batchSize is returned

Notes:
After a lengthy debugging session, we discovered the following. Hopefully it will guide you to a solution.

  • BatchCursor.Next() calls  legacyGetMore, which appends batchSize documents to currentBatch.Data
  • If limit < batchSize, numToReturn is a negative number. This may or may not be causing problems. Hard for us to tell as outsiders. This should probably be a short circuit condition
  • An extra network request is made. This causes more documents to be added to bc.currentBatch.Data. Limit is not being honored, as there is no logic similar to NewLegacyBatchCursor #118-#126 in legacyGetMore.


 Comments   
Comment by Githook User [ 15/Apr/19 ]

Author:

{'name': 'iwysiu', 'username': 'iwysiu', 'email': 'isabella.siu@10gen.com'}

Message: GODRIVER-956 fix legacyGetMore

Change-Id: I28a7702b5f00f6de99cab45e9780c43574cc5b58
Branch: release/1.0
https://github.com/mongodb/mongo-go-driver/commit/53dc4c0d793cdfa004b6ab8bab734b6dcb7f2249

Comment by Jeremy Loy [ 15/Apr/19 ]

Awesome! Thank you for the quick fix Isabella

Comment by Githook User [ 15/Apr/19 ]

Author:

{'email': 'isabella.siu@10gen.com', 'name': 'iwysiu', 'username': 'iwysiu'}

Message: GODRIVER-956 fix legacyGetMore

Change-Id: I28a7702b5f00f6de99cab45e9780c43574cc5b58
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/181353310ab82b5e6cfee218c62a47209aff9b30

Comment by Jeremy Loy [ 12/Apr/19 ]

@iwysiu and @Jeff.yemin I applied changest #4 locally for testing, and it does not work, however #3 does.

The simple change was as follows:

if numToReturn <= 0 {
	err = bc.Close(ctx)
	if err != nil {
		bc.err = err
	}
	return
}

The only change I made is moving the "return" statement outside of the err check. Simple mistake, but one that should be caught by tests/CI.

I would make this change in Gerrit, but I cannot login, I keep getting an Internal Server Error.

Comment by Isabella Siu (Inactive) [ 11/Apr/19 ]

code review url: https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/450972

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