Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUST-1048 support something like get_default_database from client? #475

Closed
WindSoilder opened this issue Sep 29, 2021 · 4 comments · Fixed by #488
Closed

RUST-1048 support something like get_default_database from client? #475

WindSoilder opened this issue Sep 29, 2021 · 4 comments · Fixed by #488
Assignees
Labels
tracked-in-jira Ticket filed in Mongo's Jira system

Comments

@WindSoilder
Copy link
Contributor

WindSoilder commented Sep 29, 2021

Let's say that I have the following code:

use mongodb::sync::Client;
let cli = Client::with_uri_str("mongodb://localhost:21017/test_db").unwrap();

It's good that we can fetch default database like this:

assert_eq!(cli.get_default_databse(), Some("test_db"));

If I have the following code:

use mongodb::sync::Client;
let cli = Client::with_uri_str("mongodb://localhost:21017/").unwrap();

then cli.get_default_database can return None.

Connection string reference: https://docs.mongodb.com/manual/reference/connection-string/

@patrickfreed
Copy link
Contributor

Hi @WindSoilder, thanks for the suggestion! Could you provide an example use case for this? For some context, in drivers (as opposed to the shell), the default database isn't used for much besides being the default auth source for certain auth mechanisms (e.g. SCRAM-SHA-256).

@WindSoilder
Copy link
Contributor Author

It's mainly used for application config or cli arguments.

Let's take mongodump as example, we can use mongodump like this:

mongodump --uri="mongodb://mongodb0.example.com:27017/test_db"

To dump only test_db, if we don't have the feature to get default datbaase, we have to use it like this:

mongodump --uri="mongodb://mongodb0.example.com:27017/" --db test_db

which is more complicated than the first one. For application involves more database instance, we can just use many urls for each mongodb instance, rather than specific every database explicitly

@patrickfreed
Copy link
Contributor

Makes sense, I filed RUST-1048 to discuss with the team at our triage meeting on Monday. Thanks again for filing this issue!

@patrickfreed patrickfreed added the tracked-in-jira Ticket filed in Mongo's Jira system label Oct 8, 2021
@patrickfreed patrickfreed changed the title [Idea] support something like get_default_database from client? RUST-1048 support something like get_default_database from client? Oct 8, 2021
@patrickfreed
Copy link
Contributor

After discussing with the team, we agree that this would be a useful feature to have. We're not sure when we'll be able to get around to implementing it, but we'd be happy to accept a pull request if you were interesting in contributing it!

We think the API changes would include the following:

  • A new Option<String> on ClientOptions called default_database
  • A new method on Client called default_database(&self) -> Option<&str>
    • Though, I wonder if this would be more ergonomic if it actually returned an Option<Database>

Let me know if you have any other questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants