[GODRIVER-2953] Make setting journaled=true on a write concern easier Created: 22/Aug/23  Updated: 06/Sep/23

Status: Backlog
Project: Go Driver
Component/s: Read and Write Concern
Affects Version/s: 1.12.0
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-2954 Make defining a "majority" write conc... Closed
is related to GODRIVER-2685 Simplify "writeconcern" API Closed

 Description   

The new API for creating a write concern (added in v1.12.0) makes defining write concerns like "w:majority, j:true" somewhat awkward. It requires users to set the Journal field, which is a *bool. Go does not have a syntax for bool pointer literals, so you have to write

writeConcern := writeconcern.Majority()
j := true
writeConcern.Journal = &j

or

writeConcern := &writeconcern.WriteConcern{
	W:       writeconcern.Majority().W,
	Journal: writeconcern.Journaled().Journal,
}

This is a feature request from https://github.com/mongodb/mongo-go-driver/pull/1331.

Definition of done:

  • Improve the API for enabling journaling on write concerns.


 Comments   
Comment by Felipe Gasper [ 05/Sep/23 ]

Maybe consider a “builder” pattern for this, e.g.:

wc := writeconcern.Majority().WithJournal(true)

Comment by Matt Dale [ 22/Aug/23 ]

One way to improve the API is to add a setter method SetJournal(bool) which would allow passing a bool literal.

E.g. write concern construction using SetJournal:

writeConcern := writeconcern.Majority()
writeConcern.SetJournal(true)

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