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-299though 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.