mongodb - Grails 3安装application.yml生产mongodb

标签 mongodb grails grails-3.0

如何设置在生产环境中使用mongodb的use connectionstring。

development:
        grails:
            mongodb:
                connectionString: "mongodb://localhost:27017/fanfest"

    production:
        dataSource:
            dbCreate: update
            url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
            properties:
                jmxEnabled: true
                initialSize: 5
                maxActive: 50
                minIdle: 5
                maxIdle: 25
                maxWait: 10000
                maxAge: 600000
                timeBetweenEvictionRunsMillis: 5000
                minEvictableIdleTimeMillis: 60000
                validationQuery: SELECT 1
                validationQueryTimeout: 3
                validationInterval: 15000
                testOnBorrow: true
                testWhileIdle: true
                testOnReturn: false
                jdbcInterceptors: ConnectionState
                defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

使用Grails 3版本。能够在开发环境中与mongodb连接。请提供一些建议在生产环境中设置mongodb。

最佳答案

当前,您有针对mongo实例的开发。生产配置指向内存中的H2数据库。如果您想为您的生产环境配置mongo数据库,我建议您看一下Mongo和GORM的Getting Started指南。

在配置文件的生产部分中,可以使用连接字符串参数,如下所示:

production {    
    grails {
        mongodb {
            connectionString = "mongodb://localhost:27017/PROD_fanfest"
        }
    }
}

请注意,由于我建议您将开发数据库和生产数据库分开,因此我使用了开发URL,但是更改了表名。配置生产数据源以使用Mongo非常简单。 Getting Started文档中描述了更多配置选项。

以下有关配置选项的相关信息:
options {
    connectionsPerHost = 10 // The maximum number of connections allowed per host
    threadsAllowedToBlockForConnectionMultiplier = 5
    maxWaitTime = 120000 // Max wait time of a blocking thread for a connection.
    connectTimeout = 0 // The connect timeout in milliseconds. 0 == infinite
    socketTimeout = 0 // The socket timeout. 0 == infinite
    socketKeepAlive = false // Whether or not to have socket keep alive turned on
    writeConcern = new com.mongodb.WriteConcern(0, 0, false) // Specifies the number of servers to wait for on the write operation, and exception raising behavior
    sslEnabled = false // Specifies if the driver should use an SSL connection to Mongo
    socketFactory = … // Specifies the SocketFactory to use for creating connections
}

关于mongodb - Grails 3安装application.yml生产mongodb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35796245/

相关文章:

javascript - 使用 mongoDB 的可排序列表

java - 使用 Spring Data,Mongodb,如何避免重复顶点错误

ruby-on-rails - 使用 Mongoid 从数据库延迟下载字段,或处理大型文档

c# - FluentMongo LINQ : How to query a sublist of a class

grails - Grails MissingPropertyException

unit-testing - Grails Interceptor模型在单元测试中为空

grails - 应用程序启动失败 Grails 3.3.0 添加 Spring Security

sql - SQL连接两个表,并在两个表之间建立链接表-GORM/Grails

mongodb - 将域类从 GORM 独立模块导入 Grails

gradle - 带有存储库镜像的Grails 3