Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add majority with journaled option on write concern option #1331

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions mongo/writeconcern/writeconcern.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ func Majority() *WriteConcern {
return &WriteConcern{W: majority}
}

// MajorityWithJournaled MajorityWithJournaled returns a WriteConcern that requests acknowledgment that
// write operations have been durably committed to the calculated majority of
// the data-bearing voting members and have been written to the on-disk journal
// on MongoDB.
//
// For more information about write concern "w: majority" and "j: true", see
// https://www.mongodb.com/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-
func MajorityWithJournaled() *WriteConcern {
journal := true
return &WriteConcern{W: majority, Journal: &journal}
}

// Custom returns a WriteConcern that requests acknowledgment that write
// operations have propagated to tagged members that satisfy the custom write
// concern defined in "settings.getLastErrorModes".
Expand Down
6 changes: 6 additions & 0 deletions mongo/writeconcern/writeconcern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ func TestWriteConcern(t *testing.T) {
wantAcknowledged: true,
wantIsValid: false,
},
{
name: "{w: majority, j: true}",
wc: writeconcern.MajorityWithJournaled(),
wantAcknowledged: true,
wantIsValid: true,
},
{
name: "{w: custom}",
wc: &writeconcern.WriteConcern{W: "custom"},
Expand Down