Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-436

MongoURI ignores username, password, database

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.10.0
    • Affects Version/s: 2.5.3
    • Component/s: API
    • Labels:
      None

      If you try to deploy to Heroku and use the MongoHQ addon (which is probably the easiest way to use Mongo on Heroku), the MONGOHQ_URL they provide doesn't work.

      This is something like:

      mongodb://uname:pwd@host:13029/database

      So MongoDB isn't usable with Java on Heroku as best I can tell. I guess they only tested Ruby

      In debugging this, there seemed to be two problems, at least with 2.5.3:

      • Mongo(uri) ignores the username, password, port, and most of the options
      • MongoURI doesn't parse them correctly anyhow, this was JAVA-299 though I think (fixed just after 2.5.3)

      I guess technically it should be MongoURI.connectDB() that does the db.authorize() - there's a "// TODO auth" comment in there, but the patch I think is barely longer than the comment, maybe:

      • // TODO auth
      • return connect().getDB( _database );
        + DB db = connect().getDB(_database);
        + if (_username != null && _password != null)
        + db.authenticate(_username, _password);
        + return db;

      Fixing Mongo(uri) is mildly more involved because it has to parse the port out of each host.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            hp Havoc Pennington
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: