Grails 3 Setup application.yml production mongodb

蹲街弑〆低调 提交于 2019-12-10 12:05:54

问题


How to set the use connectionstring which usess mongodb in production.

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

Working with Grails 3 version. Able to connect with mongodb in development environment. Kindly provide some suggestions to set the mongodb in production environment.


回答1:


You currently have development pointing at a mongo instance. The production configuration is pointed at the in memory H2 database. If you would like to configure a mongo database for your production environment may I suggest you take a look at Getting Started guide for Mongo and GORM.

In the production section of your configuration file you can use the connection string parameter as follows:

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

Please note I have used your development URL but changed the table name since I recommend you keep the development database and production database separate. Configuring production datasource to use Mongo is that easy. There are more configuration options described in the Getting Started documentation.

Relevant information on configuring options below:

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
}


来源:https://stackoverflow.com/questions/35796245/grails-3-setup-application-yml-production-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!