-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
Expected Behavior
As a developer passing both a connection string and a MongoClientOptions object,
I expect the programmatic value to win for every option, as documented on MongoClient ("The programmatically provided options take precedence over the URI options.")
When the same setting is provided in both places, either under the same option name or under different option names that configure the same thing.
Actual Behavior and Impact
- parseOptions collects the programmatic value first and the URI values after it, and most options use only the first value, so the programmatic value wins. Two kinds of cases don't follow this:
- Same option, transform reads every value: authMechanismProperties (merged key by key, URI keys overwrite programmatic ones) and compressors (union of both).
- Different options with the same target: transforms run in OPTIONS declaration order and build on the current value, so a URI option declared later overwrites an earlier programmatic one (readConcern, readPreference tags, writeConcern journal/wtimeout).
- Examples (programmatic options + URI, resolved value):
{ authMechanismProperties: { SERVICE_NAME: 'a' } } + ?authMechanismProperties=SERVICE_NAME:b // 'b' { compressors: ['zstd'] } + ?compressors=zlib // ['zstd', 'zlib'] { readConcern: { level: 'local' } } + ?readConcernLevel=majority // 'majority' { readPreference: { mode: 'secondary', tags: [{ dc: 'a' }] } } + ?readPreferenceTags=dc:b // [{ dc: 'b' }] { writeConcern: { journal: true } } + ?journal=false (or ?j=false) // false { writeConcern: { wtimeoutMS: 100 } } (or { wtimeoutMS: 100 }) + ?wtimeout=200 // 200 { journal: true } + ?j=false // false - Contradicts the documented precedence.
Dependencies
- None.
Risks/Unknowns
- Apps that rely on the URI overriding or extending these options will see a behavior change. This is a breaking change and needs to ship in a major release.
- The connection-string spec leaves precedence to each driver (it only recommends the URI wins), so no cross-driver change is needed.
Acceptance Criteria
Implementation Requirements
- authMechanismProperties: programmatic keys win on collision; keys set only in the URI are still merged in.
- compressors: when set programmatically, the programmatic list is used as is.
- readConcern, readPreference, writeConcern: resolve from programmatic options first and fill gaps from the URI, independent of OPTIONS declaration order.
Testing Requirements
- A unit test for each example above, asserting the programmatic value wins.
- A unit test that URI-only authMechanismProperties keys are still merged in.
Documentation Requirements
- Release note describing the behavior change.
Follow Up Requirements
- None.