[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:
Related
related to GODRIVER-914 Configure Database Name From Mongo URI Closed

 Description   

Add a named parameter to the URI to support default db
Add client APIs to "use" the specified 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:

If a driver provides an API for accessing a default database, that driver MUST infer the default database's name from the `/database` component of the URI

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.:

$ mongodump -v --uri=mongodb://localhost/foo
2019-06-03T15:51:48.442-0400    dumping up to 1 collections in parallel
2019-06-03T15:51:48.442-0400    writing foo.bar to
2019-06-03T15:51:48.445-0400    done dumping foo.bar (1 document)

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 ]

What we need is for all drivers to have a well defined way to get a database instance with that name from MongoClient.

I'm not sure where this requirement is coming from (outside of the feature request in GODRIVER-914), but I'd question the necessity of introducing such an API on all drivers at this point in time.

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?
As stated in that spec the path component is the authentication database but it does not indicate it being the default for any other purpose.

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:

mongodb://user:password@host/database

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:

https://api.mongodb.com/python/current/api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient.get_default_database

Generated at Thu Feb 08 08:22:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.