Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ private String getNamespaceDescription(final CollectionsConfig collectionsConfig
}

private WriteConcern createWriteConcern() {
WriteConcern writeConcern = WriteConcern.ACKNOWLEDGED;
WriteConcern writeConcern = getConnectionString().getWriteConcern();
if (writeConcern == null) {
writeConcern = WriteConcern.ACKNOWLEDGED;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional]

To make it obvious for a code reader that the default write concern is the same as that in the MongoClientSettings, we could write MongoClientSettings.builder().build().getWriteConcern() instead of WriteConcern.ACKNOWLEDGED.

We may further document on WriteConfig.WRITE_CONCERN_W_CONFIG that the default write concern is the same as the one used by MongoClientSettings, which is WriteConcern.ACKNOWLEDGED.

}
try {
if (containsKey(WRITE_CONCERN_W_CONFIG)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ void testMongoConfigWriteConcern() {
writeConfig = writeConfig.withOption(
WriteConfig.WRITE_PREFIX + WriteConfig.WRITE_CONCERN_W_CONFIG, "region1");
assertEquals(new WriteConcern("region1"), writeConfig.getWriteConcern());

writeConfig = MongoConfig.createConfig(CONFIG_MAP).toWriteConfig();
writeConfig.withOption(MongoConfig.CONNECTION_STRING_CONFIG, "mongodb://localhost/");
assertEquals(WriteConcern.ACKNOWLEDGED, writeConfig.getWriteConcern());

writeConfig = writeConfig.withOption(
MongoConfig.CONNECTION_STRING_CONFIG, "mongodb://localhost/?w=majority");
assertEquals(WriteConcern.MAJORITY, writeConfig.getWriteConcern());

// Explicit configuration beats connection string
writeConfig = writeConfig.withOption(WriteConfig.WRITE_CONCERN_W_CONFIG, "3");
assertEquals(3, writeConfig.getWriteConcern().getW());
}

@Test
Expand Down