2016-03-04 70 views
0

如何設置在生產中使用mongodb的使用connectionstring。Grails 3安裝application.yml生產mongodb

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。

回答

1

您目前正在開發指向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 
} 
+0

感謝俺們!將有任何數據庫連接超時 –

+0

請參閱我的答案中的入門鏈接文檔。 – Nathan