mongodb / mongo-jdbc-driver

JDBC Driver for MongoDB Atlas SQL interface
Apache License 2.0
37 stars 33 forks source link

ISSUE #33: Passing database via connection string doesn't work #49

Closed mmpataki closed 1 year ago

mmpataki commented 2 years ago

Database name specified in the connection string is not honored. With this change one can specify a db name as jdbc:mongodb://foo:foopass@localhost:27017/admin?database=mydatabase

rychipman commented 2 years ago

Hi @mmpataki,

In the [documentation for the MongoDB URI|https://docs.mongodb.com/manual/reference/connection-string/], you'll see that the database name after the / is not actually a database to connect to, but rather the default auth database.

The JDBC driver allows users to specify the database to connect to via the database key in the Properties object passed into the MongoConnection constructor.

mmpataki commented 2 years ago

Hi @rychipman I believe there should be a way to pass those props via connection string which is not possible without this patch applying this patch allows one to pass dbname through connection string

Users sometimes don't have luxury of passing a props object eg. external library and this shouldn't cause a NPE. Please check the test i added

pmeredit commented 2 years ago

@rychipman @mmpataki I'm in favor of supporting this, but we should talk to product

mmpataki commented 2 years ago

@pmeredit @rychipman you guys had a discussion?

GavinRay97 commented 2 years ago

I am pretty sure you can do this, right? In my app I am connecting like this:

mongodb://root:password@localhost:27017/sample?authSource=admin
terakilobyte commented 1 year ago

@mmpataki We've decided to match the way the drivers handle the default database in the URI, i.e. mongodb://server/db?authSource=admin&otherProps, see #122 . cc @nbagnard and @pmeredit

terakilobyte commented 1 year ago

Closing this issue as #122 resolves this. Users will be able to specify a default db in the URI on the next release.