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

Simplify "writeconcern" API

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

      1. What would you like to communicate to the user about this feature?
      There is a new standard syntax for defining write concerns in the Go driver.

      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      Yes. All examples showing how to specify a write concern should be updated to use the new syntax.

      At least the following pages contain examples that should be updated:

      3. Which versions of the driver/connector does this apply to?
      v1.12+

      Show
      1. What would you like to communicate to the user about this feature? There is a new standard syntax for defining write concerns in the Go driver. 2. Would you like the user to see examples of the syntax and/or executable code and its output? Yes. All examples showing how to specify a write concern should be updated to use the new syntax. At least the following pages contain examples that should be updated: https://www.mongodb.com/docs/drivers/go/upcoming/fundamentals/crud/write-read-pref/ https://www.mongodb.com/docs/drivers/go/upcoming/fundamentals/transactions/ 3. Which versions of the driver/connector does this apply to? v1.12+

      The writeconcern package and types use a lot of unnecessary APIs that can confuse users. Additionally, there is no shortcut for specifying common write concerns like there is for the readconcern and readpref packages. We should remove the functional options pattern and just export all fields in the WriteConcern struct so users can set them directly. We should add package functions for quickly specifying common write concerns "majority", "w: 0", and "w: 1".

      Also, some exported values or functions do not need to be exported:

      • ErrInconsistent, ErrEmptyWriteConcern, ErrNegativeW, ErrNegativeWTimeout - Unless users are dynamically building write concerns at application time, these error are unrecoverable and do not need to support special conditional logic (i.e. if err == ErrInconsistent).
      • WriteConcern.MarshalBSONValue - The single known use case outside of the Go driver is in mongorestore, which uses it to make a copy of a write concern. That use case is removed by exporting the write concern fields.

      Definition of done:

      • Add package functions for creating common write concerns
        • Majority
        • W0
        • W1
        • Custom(tag string)
      • Export all fields in the WriteConcern struct and add documentation for what each field does and what values are valid.
        • When exporting the J field, change it to type *bool so we can represent either true, false or unset. Also update the logic to only exclude J from the marshaled document if it's unset, but always include explicit true or false.
      • Deprecate Option type and all Option functions.
      • Deprecate New.
      • Deprecate all error values.
      • Deprecate WriteConcern.MarshalBSONValue

      Note that all deprecated code will be removed or unexported in Go Driver 2.0.

            Assignee:
            matt.dale@mongodb.com Matt Dale
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: