mongodb - 如何为 mongodb 副本集配置 grails 3

我正在将 grails 3 应用程序部署到实时服务器。一个 mongodb 实例已在复制模式下设置并在 live box 中成功测试。我测试过:

mongo -u uname -authenticationDatabase dbname ip-1.ec2.internal:27017/dbname -p password

我使用了指定的 replicaSetconnectionString here和 here .但在这两种情况下,它的行为都好像没有提供主机配置,因此默认为 localhost。而且由于没有设置它失败。这是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"
        }

我使用的是最新版本:

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

以下是插件及其版本的列表:

compile 'org.grails.plugins:mongodb:6.1.0'
compile 'org.grails:grails-datastore-rest-client:6.0.9.RELEASE'

这是我遇到的错误:

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

我现在已经用完了选项,有人可以在这里指点帮助我吗?谢谢。

最佳答案

connection strings正如詹姆斯克利所建议的那样,解决了这个问题。这就是我引用 example 使用它的方式:

mongodb {
    url = "mongodb://ip-1.ec2.internal,ip-2.ec2.internal,ip-3.ec2.internal/?replicaSet=hostname-of-mongod-instance"
    port = 27017
    ...
}

https://stackoverflow.com/questions/43255334/

相关文章:

java - 从 JAVA 应用程序使用 SSL 连接到 MongoDb

javascript - 如何在 Node 议程中以编程方式定义多个具有相同名称的作业

python - 大内存 Python 后台作业

node.js - mongoose.connection.collections.collecti

mongodb - 语法错误 : missing ) after argument list @(s

node.js - 如何在 Mongoose 中定义排序函数

node.js - Mongoose(或类似的 ODM)内存记录注册表?

javascript - 如何将文件名设置为与数据库中的对象 ID 相同?

mongodb - 如何使用 electron 和 pouchdb 创建一个持久的离线数据库

mongodb - 为什么 mongo dot notation 会替换整个子文档?