user1094976
user1094976

Reputation:

Getting mongodb authentication failed error

I'm using playframework -v 1.2.4, and using the morphia plugin. When I run play test, and connect with mongolab db, an exception is thrown with the following error:

Oops: RuntimeException
An unexpected error occured caused by exception RuntimeException:
MongoDB authentication failed: mydb

My application.conf as follows..,

application.mode=dev
%prod.application.mode=prod
morphia.db.host=ds033187.mongolab.com
morphia.db.port=33187
morphia.db.username=demo
morphia.db.password=demo
morphia.db.name=mydb

But the above credentials are able to connect with mongodb

D:\mongodb-win32-i386-2.0.1\bin>mongo ds033187.mongolab.com:33187/mydb -u demo -p demo
MongoDB shell version: 2.0.1
connecting to: ds033187.mongolab.com:33187/mydb
>

But i get connection with mongodb shell. Why i'am getting this error?

Upvotes: 1

Views: 2427

Answers (2)

kritzikratzi
kritzikratzi

Reputation: 20231

had the exact same problem. i suppose you added the user via

use admin
db.addUser( "user", "pw" ) 

however, play morphia does seem to authenticate against the very db you're using, not against the admin db. the following solved my problem:

/path/to/mongo
use admin
db.auth( "user", "pw" )
use myDatabase
db.addUser( "user", "pw" ) 

now it should work :)

Upvotes: 0

Nican
Nican

Reputation: 7935

I am assuming that you are using the PlayMorphia module, and taking a quick look at the documentation, it uses "morphia.db.seeds" instead of "morphia.db.host".

It could be that, since "seeds" is not specified, the morphia module is connecting to the localhost.

Upvotes: 1

Related Questions