【发布时间】:2016-05-23 17:37:54
【问题描述】:
我一直在努力让 grails 3.1.7 连接到本地 mongo db。我已经通过main documentation 实施了各种建议。我通过Alex M 和Armarnath 浏览了一些关于stackoverflow 的帖子
我的 build.gradle 如下所示:
// ...
compile 'org.grails.plugins:mongodb'
compile "org.mongodb:mongodb-driver:3.0.2"
runtime 'org.springframework.data:spring-data-mongodb:1.8.1.RELEASE'
//compile 'org.mongodb:mongo-java-driver'
//compile("org.grails:gorm-mongodb-spring-boot:5.0.6.RELEASE")
//compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
//compile "org.hibernate:hibernate-ehcache"
// ...
我的 application.yml 看起来像下面的 sn-p:
//...
environments:
development:
dataSource:
grails:
mongodb:
connectionString: "mongodb://localhost:27017/project-db"
# dbCreate: create-drop
# url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
dataSource:
# dbCreate: update
# url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSource:
# dbCreate: update
# url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
# properties:
# jmxEnabled: true
//...
这是一个示例模型:
class FlowInfo {
int posIndex
String tagName
Boolean isEnabled
String name
static mapWith="mongo"
static constraints = {
posIndex unique: true
}
}
看起来我仍在从可能在 BootStrap.groovy 播种的第一次运行时创建的第一个初始内存数据库中提取数据。有没有办法使这项工作。看起来不同的策略适用于不同的人。
感谢您阅读本文。
【问题讨论】:
-
您是否尝试过在您的域中使用
static mapWith = "mongo"属性? -
抱歉回复晚了。我确实有 mapWith
标签: mongodb grails grails-orm