[JAVA-2135] MongoClient object accepts setWriteConcern which seems to have no effect Created: 02/Mar/16 Updated: 18/Mar/16 Resolved: 18/Mar/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API, Write Operations |
| Affects Version/s: | 3.0.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Asya Kamsky | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
The following code snippet does not set WriteConcern on the MongoDatabase instance as might be expected:
|
| Comments |
| Comment by Jeffrey Yemin [ 03/Mar/16 ] |
|
See related ticket |
| Comment by Jeffrey Yemin [ 03/Mar/16 ] |
|
I see the issue. The MongoClient.getDatabase method constructs a MongoDatabase instance with the write concern (and read preference) from MongoClientOptions instance rather than its own write concern (and read preference) property, which is initialized from MongoClientOptions but then can be changed via Mongo#setWriteConcern. Mongo#getDB works as expected. In practice, it's much more common for users to override WriteConcern default via MongoClientOptions or MongoClientURI, but as setWriteConcern is still supported, this should still be considered a bug. |
| Comment by Asya Kamsky [ 02/Mar/16 ] |
|
Workarounds or scenarios that do work correctly:
The only combination that doesn't work is the old way of setting writeConcern on the client and the new getDatabase method. |