I’m using Jmongo 1.1.5 in a Rails app running under Jruby 1.6.7
I’m attempting to connection to a mongodb instance with authentication enabled.
I don’t have any trouble doing this from the mongo CLI tool using db.auth(‘user’, ‘pass’).
In my Jruby app I connect like this:
client = Mongo::Connection.new
db = client.db('my_database')
db.authenticate('user', 'pass')
I don’t have trouble using mongo this way when the server doesn’t run with –auth.
The #authenticate call always returns false with valid creds. Digging further,
I found an exception caught and eaten inside the gems/jmongo-1.1.5/lib/jmongo/db.rb:
caught in authenticate: user: cannot convert instance of class
org.jruby.RubyString to
class [C lib/jmongo/db.rb:50:in `authenticate'
(I hacked the gem’s db.rb to see the exception)
Has anyone seen something like this?
It turns out to be a jmongo bug fixed in
https://github.com/marclove/jmongo/commit/788244d6b575d49715809e7668e3ad548951e6b6
To work around this issue, wrap password like this: