Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-3049

Replace bsoncore.DocumentSequence with a bson type-agnostic analogue

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Not Needed
    • Hide

      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?

      Show
      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?

      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.

            Assignee:
            preston.vasquez@mongodb.com Preston Vasquez
            Reporter:
            preston.vasquez@mongodb.com Preston Vasquez
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: