-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Not Needed
-
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.
- is depended on by
-
GODRIVER-2443 Make Distinct return a decodable struct "[]any"
- Closed