Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1258

Using database name from URI

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.6
    • Affects Version/s: 3.0.1
    • Component/s: Native
    • Environment:
      Windows 7

      In 2.x versions of the Node.js driver, I was able to configure the database name via the connection string, for example mongodb://localhost/foobar

      I have built applications that only read the connection URI from configuration and can then connect to the specified database without having to pass in the database name as a separate string anywhere in the code.

      Version 3.x of the driver no longer seems to support this use case, as instead of the Db object, I get a Client object from connect() and in order to get a Db object from that, I need to provide the database name as a separate string.

      Does this mean I will need to update these applications to use two separate configuration variables (connection string and database name)?

      Is the database name in the connection string now ignored or is there still a way to have the driver use it as the default?

      I could, of course, add separate functionality for parsing the db name from the connection string, but it seems more elegant if this was handled inside the driver. Or if not automatically like 2.x versions did, perhaps its URL parser could be exposed through the public API?

      I've noticed that the database name from the connection string is actually still accessible via client.s.options.dbName but I'm guessing this is an internal implementation detail that is not guaranteed to work in future versions.

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            mjomble Andres Kalle
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: