I am deploying a grails 3 application on a real server. The mongodb instance was configured in replication mode and successfully tested in real time. I tested with:
mongo -u uname -authenticationDatabase dbname ip-1.ec2.internal:27017/dbname -p password
I used replicaSetboth connectionStringas indicated here and here . But in both cases, it behaves as if no host configuration has been configured, so localhost is used by default . And since it is not configured, it fails. Here is the application.groovy :
mongodb {
replicaSet = [ "ip-1.ec2.internal", "ip-12.ec2.internal", "ip-3.ec2.internal"]
host = "ip-1.ec2.internal" //This works for any of the hosts
port = 27017
username = "username"
password = "password"
databaseName = "dbname"
}
I am using the latest versions:
grailsVersion=3.2.8 //It was the same for 3.2.5
gormVersion=6.0.9.RELEASE
gradleWrapperVersion=3.4.1 //It was the same for 3.0
Here is a list of plugins with their versions:
compile 'org.grails.plugins:mongodb:6.1.0'
compile 'org.grails:grails-datastore-rest-client:6.0.9.RELEASE'
And this is the error I encountered:
01:22:26.410 - [localhost-startStop-1] INFO org.mongodb.driver.cluster - No server chosen by
ReadPreferenceServerSelector{readPreference=primary} from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE,
all=[ServerDescription{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException:
Exception authenticating MongoCredential{mechanism=null, userName='username', source='dbname', password=<hidden>,
mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18:
'Authentication failed.' on server 127.0.0.1:27017. The full response
is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }}}]}. Waiting for 30000 ms before timing out
Now I have run out of options, can someone point out help me here? Thank.