[Question] Obtain DefaultDb instance while using URI as connection parameter

10 views
Skip to first unread message

Юрий Анкудинов

unread,
Oct 1, 2015, 10:41:44 AM10/1/15
to ReactiveMongo - http://reactivemongo.org

Hi,
I want to use mongo URI like mongodb://localhost:27017/db_name to construct MongoConnectionobject like it shown in docs

val driver = new MongoDriver
MongoConnection.parseURI(uri)
  .map(parsedUri => driver.connection(parsedUri)).get

Is it possible to retrieve the DefaultDB object out of the connection object without specifying db name explicitly as far as far as it already presented in the URI?

Something like:

val driver = new MongoDriver
MongoConnection.parseURI(uri)
  .map(parsedUri => driver.connection(parsedUri))
  .map(connection => connection.db()).get // as far as URI includes db name should be possible get the DB instance without specifying the name

Now I am doing it in that way:

val driver = new MongoDriver
MongoConnection.parseURI(uri)
  .map(parsedUri => driver.connection(parsedUri))
  .map(connection => connection.db("db_name")).get // db name provided explicitly

Cédric Chantepie

unread,
Oct 1, 2015, 4:58:08 PM10/1/15
to ReactiveMongo - http://reactivemongo.org
The connection URI requires the DB name. If you want choose it later, you can either build dynamically the URI string, or have a look at the other constructors on MongoConnection
Reply all
Reply to author
Forward
0 new messages