-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Needed
-
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.
- is depended on by
-
GODRIVER-2696 Use an options pattern that doesn't require merging structs
- Closed
- is duplicated by
-
GODRIVER-1179 Reference to "WTagSet" when configuring write concern
- Closed
- is related to
-
GODRIVER-964 make option type construction consistent with the options package (e.g. readpref, readconcern, writeconcern)
- Closed
- related to
-
GODRIVER-2953 Make setting journaled=true on a write concern easier
- In Progress
-
GODRIVER-2812 Make "WriteConcern" struct parameterized to accept either int or string for W
- Closed