mongo-rs icon indicating copy to clipboard operation
mongo-rs copied to clipboard

Input the database name through a URI

Open magiclen opened this issue 4 years ago • 4 comments

A database name can be included in a mongo URI,

mongodb://$[hostlist]/$[database]?authSource=$[authSource]

The Client struct in this crate seems to aim to operate collections within a single database. Why not just parse the database in the URI to build the Client instead of using the database method of a ClientBuilder?

magiclen avatar Apr 28 '21 13:04 magiclen

Hmm I am not opposed, but does this add anything apart from hiding stuff away? We could do the same thing for auth too but IMO using the builder is cleaner. We could always update it so that you can pass a complete URL or use the builder.

What is the use case you are thinking of? Or is the issue, that with the current client design a new client is required for each database being interacted with? The library currently only addresses our use cases so I would not be surprised if it can be improved in areas.

alexkornitzer avatar Apr 29 '21 13:04 alexkornitzer

When I use Docker to build debenv, its help, and sometimes the Witch Part I don't really care about, is the username or password

1216892614 avatar Oct 17 '22 13:10 1216892614

Okay so we could just extend uri here so that we parse with url and if auth, path etc are set then we set them in the builder. We can then add a with_uri to the Client. Would that be sufficient?

alexkornitzer avatar Oct 17 '22 14:10 alexkornitzer

cool

1216892614 avatar Oct 18 '22 01:10 1216892614