[CDRIVER-2817] Are duplicates for all URI options parsed consistently? Created: 07/Sep/18  Updated: 28/Oct/23  Resolved: 21/Sep/18

Status: Closed
Project: C Driver
Component/s: docs, uri
Affects Version/s: None
Fix Version/s: 1.14.0

Type: Task Priority: Minor - P4
Reporter: Jeremy Mikola Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

If the same option appears multiple times in a connection string (e.g. connectTimeoutMS) with either the same or different spellings, how is its value stored and later retrieved? Does the last occurrence always take precedence?

Furthermore, is behavior consistent for special URI options that may a struct field (e.g. auth or SSL options) and generic options that set a key in the bson_t within a URI struct and are later looked up with a generic get method (e.g. connectTimeoutMS)?

For context, the connection string spec states:

  • Keys are strings and the character case must be normalized by lower casing the uppercase ASCII characters A through Z; other characters are left as-is. (source)
  • If a key is repeated and the corresponding data type is not a List then the precedence of which key value pair will be used is undefined. Where possible, a warning SHOULD be raised to inform the user that multiple options were found for the same value. (source)


 Comments   
Comment by Githook User [ 21/Sep/18 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@10gen.com', 'username': 'kevinAlbs'}

Message: CDRIVER-2817 do not add compressors twice
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/67e3e5215e8cdd05c8116862cd839eee60444fe6

Comment by Githook User [ 20/Sep/18 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@10gen.com', 'username': 'kevinAlbs'}

Message: CDRIVER-2817 test duplicate uri opts
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/cb7b6ec80f4615e8d893e959d9379434a9a787d0

Comment by Kevin Albertson [ 13/Sep/18 ]

We make an effort to replace the existing value when parsing a duplicate option.

mongodb://localhost:27017/test?w=0&w=1&w=2

Uses "w=2". We also log a warning every time we overwrite w:

2018/09/13 16:04:30.0570: [18947]:  WARNING:       mongoc: Overwriting previously provided value for 'w'

So for most cases, the last value takes precedence. The helper functions which set the option on the mongoc_uri_t

_mongoc_uri_set_option_as_int32
_mongoc_uri_set_option_as_bool
mongoc_uri_bson_append_or_replace_key

Attempt to replace the option value whenever seeing a duplicate.

However, in digging around there seems to be at least some exceptions. For instance, a string value for "w" will replace an integer value for "w" but not vice-versa:

mongodb://localhost:27017/test?w=0&w=majority

Uses w=majority

mongodb://localhost:27017/test?w=majority&w=0

Uses w=majority (but should use w=0 for consistency)

Repeated readpreferencetags don't overwrite, but instead get appended

mongodb://localhost:27017/test?readpreference=secondary&readpreferencetags=a:1&readpreferencetags=b:1

Sets the tags to a:1, b:1

I haven't tested all cases, but I think these are the only exceptions.

Comment by A. Jesse Jiryu Davis [ 13/Sep/18 ]

To close this ticket, answer the question here and note in an appropriate place in the docs that repeated values have undefined behavior.

Generated at Wed Feb 07 21:16:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.