【发布时间】:2015-01-05 18:59:07
【问题描述】:
我在 grails 中使用 gorm 连接到 MongoDB。我得到了 MongoTimeOutException。 我能够使用 mongo java 驱动程序独立程序成功连接到 MongoDb。 为什么我无法通过 Grails GORM 插件连接?
有人可以帮忙吗? 下面是配置
grails {
mongo {
host = "localhost"
port = 27107
databaseName = "test"
options{
connectionsPerHost=20
}
}
}
下面是领域类
class Device {
String deviceType
String deviceId
int primary
static constraints = {
}
}
下面是异常跟踪
| Error 2014-11-09 16:10:39,620 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver - MongoTimeoutException occurred when processing request: [GET] /devices/Device
Timed out while waiting to connect after 10000 ms. Stacktrace follows:
Message: Timed out while waiting to connect after 10000 ms
Line | Method
->> 131 | getDescription in com.mongodb.BaseCluster
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 396 | getClusterDescription in com.mongodb.DBTCPConnector
| 569 | getType . . . . . . . in ''
| 370 | isMongosConnection in ''
| 645 | isMongosConnection . in com.mongodb.Mongo
| 454 | _check in com.mongodb.DBCursor
| 546 | _hasNext . . . . . . in ''
| 571 | hasNext in ''
| 1893 | hasNext . . . . . . . in org.grails.datastore.mapping.mongo.query.MongoQuery$MongoResultList$1
| 8 | index in ewents.DeviceController
| 198 | doFilter . . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 895 | runTask . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
| 918 | run in ''
^ 695 | run . . . . . . . . . in java.lang.Thread
或者有人可以分享带有 GORM 支持的示例 Grails 示例吗?我基本上是这个 Grails 的新手。
【问题讨论】:
-
显然,grails 无法连接到位于 localhost:27017 的 MongoDB 服务器。您是否尝试过通过 mongo shell 或 telnet 访问它?
-
是的,可以通过 mongo shell 访问。但是,为什么 Grails 不能连接到 localhost:27017 而一个独立的 Java 类可以呢?
-
两者都在同一台机器上,我猜?请提供您用于连接的确切命令行。
标签: mongodb grails groovy grails-orm