[DRIVERS-662] Add a URI param and supporting API to enable a default database Created: 03/Jun/19 Updated: 13/Apr/20 Resolved: 13/Apr/20 |
|
| Status: | Closed |
| Project: | Drivers |
| Component/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Scott L'Hommedieu (Inactive) | Assignee: | Unassigned |
| Resolution: | Won't Do | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
Add a named parameter to the URI to support default db |
| Comments |
| Comment by Jeremy Mikola [ 03/Jun/19 ] | ||||
|
Just saw behackett's response in Slack about preferring not to use a new URI option. In that case, I'd propose the following spec language:
| ||||
| Comment by David Golden [ 03/Jun/19 ] | ||||
|
The URI path database is not spec'd as the default for any other purpose than auth, but in the wild, it is used as such. E.g.:
Spelunking into history, the authSource parameter appears to be introduced to an early draft about driver auth for what later became the auth spec in this wiki page: https://wiki.corp.mongodb.com/pages/viewpage.action?pageId=58687847&navigatingVersions=true That's before my time and the wiki has no discussion, so I have no context for why a parameter was introduced instead of using the database from the URI path – whether that URI path database was already ambiguous in usage or not. Possibly behackett, jeff.yemin or craig.wilson@mongodb.com remember. I see no reason why we couldn't enshrine the URI path database as a "default" and allow users to use it for other things than auth. | ||||
| Comment by Jeremy Mikola [ 03/Jun/19 ] | ||||
I'm not sure where this requirement is coming from (outside of the feature request in Given the historic, documented usage of /database in the URI to denote a default authentication database, I don't see any way to drivers to introduce a new concept of a non-authentication "default database" (e.g. Client.getDefaultDatabase()) without conflating the two. Have we considered introducing a defaultDatabaseName URI option and having that fall back to the /database component as authSource does? That would at least allow us to disambiguate both options while still supporting the old syntax for users that can't be bothered to upgrade. That said, I'd still prefer to see this introduced as an optional API. | ||||
| Comment by Scott L'Hommedieu (Inactive) [ 03/Jun/19 ] | ||||
|
Am I applying the connection string spec to literally? If I'm reading that correctly and if a default database (and related API) is indeed valuable, the auth DB and the default DB should be disambiguated. Whether there is only one way in the URI to set them or not is debatable but that isn't clear in the current specs. And yes an update to specs would be needed in order to describe the use of the declared default database. The definition on the use of a default database only seems dependent on such a notion of a default and not on how it is declared. | ||||
| Comment by Bernie Hackett [ 03/Jun/19 ] | ||||
|
We don't need a named parameter. Just pass the database name like so:
All drivers already support that for authentication. What we need is for all drivers to have a well defined way to get a database instance with that name from MongoClient. A number of drivers already have such an API. See for example: |