I am deploying a grails 3 app to a live server. A mongodb instance has been setup in replication mode and tested successfully from the live box. I tested with:
mongo -u uname -authenticationDatabase dbname ip-1.ec2.internal:27017/dbname -p password
I have used the replicaSet
and connectionString
as specified here and here. But in both cases it behaves as though no hosts config have been supplied thus defaulting to localhost. And since that's not set up 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 are the 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 ran into:
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
I have ran out of options now, can anyone please point help me out here? Thanks.