[GODRIVER-3049] Replace bsoncore.DocumentSequence with a bson type-agnostic analogue Created: 13/Nov/23  Updated: 13/Jan/24  Resolved: 13/Jan/24

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

Type: Improvement Priority: Unknown
Reporter: Preston Vasquez Assignee: Preston Vasquez
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by GODRIVER-2443 Make Distinct return a decodable stru... Blocked
Epic Link: Go Driver 2.0: Driver
Quarter: FY24Q3, FY24Q4
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Context

The Go Driver uses bson.DocumentSequence to represent the batch data that underlines the current position of a cursor. This type is specific to bson documents and represents the data as a low-level byte slice. This logic can be simplified while maintaining support for any bson type (albiet not necessary):

type Iterator struct {
	List Array // List of BSON values
	pos  int   // The position of the iterator in the list in reference to Next()
}
 
// Count returned the number of elements in the iterator's list.
func (iter *Iterator) Count() int {}
 
// Empty returns true if the iterator's list is empty.
func (iter *Iterator) Empty() bool {}
 
// Reset will reset the iteration point for the Next method to the beginning of
// the list.
func (iter *Iterator) Reset() {}
 
// Documents traverses the list as documents and returns them. This method
// assumes that the underlying list is composed of documents and will return
// an error otherwise.
func (iter *Iterator) Documents() ([]Document, error) {}
 
// Next retrieves the next value from the list and returns it. This method will
// return io.EOF when it has reached the end of the list.
func (iter *Iterator) Next() (*Value, error) {}

Definition of done

What must be done to consider the task complete?

Replace the bsoncore.DocumentSequence with the iterator pattern proposed in this POC PR: https://github.com/mongodb/mongo-go-driver/pull/1411/files#diff-3d1e0c824f377621943c638e3ae47a4a0bf8107a3353cdfe9f13c989eae3d0a3

Pitfalls

What should the implementer watch out for? What are the risks?

The performance impact should be the same between these two solutions, but it would be ideal to create a benchmark for the Iterator. This logic will be used in every cursor type, which means that it has a high-level of exposure to users. Fuzz testing could be beneficial.



 Comments   
Comment by Githook User [ 13/Jan/24 ]

Author:

{'name': 'Preston Vasquez', 'email': 'prestonvasquez@icloud.com', 'username': 'prestonvasquez'}

Message: GODRIVER-3049 Replace bsoncore.DocumentSequence with a bson type-agnostic analogue (#1492)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/12a97f78f889b2cfd9094c558eafe338c2d6bd59

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