我正在尝试将 ColdFusion 2016(本地机器开发人员模式)连接到 MongoDB 4.0.13(服务器)。我将 mongodb-driver-core-3.8.2.jar、bson-3.8.2.jar 和 mongodb-driver-3.8.2.jar 安装到我的 lib 文件夹中。当我尝试运行此代码时,它永远不会连接到 Mongo,它会出错。我没有使用正确的驱动程序吗?
代码:
<cfset uri = CreateObject("java","com.mongodb.MongoClientURI").init("mongodb://wh-mongos-v01.shift4.com:27017")>
<cfset mongoClient = CreateObject("java","com.mongodb.MongoClient").init(uri)>
<cffunction name="m" returntype="any">
<cfargument name="value" type="any">
<cfif IsJSON(arguments.value)>
<cfset local.retrun = CreateObject("java","com.mongodb.util.JSON").parse(arguments.value)>
<cfelse>
<cfset local.retrun = CreateObject("java","com.mongodb.util.JSON").parse( SerializeJSON(arguments.value) )>
</cfif>
<cfreturn local.retrun>
</cffunction>
<cfset myDb = mongoClient.getDatabase("testingdb")>
<cfset myCollection = myDb.getCollection("testingcollection")>
<cfdump var="#myCollection.countDocuments()#">
错误:等待连接时在 30000 毫秒后超时。集群状态的客户端视图是 {type=UNKNOWN, servers=[{address=wh-mongodb-v01.xxxxx.com:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely达到end of溪流}}]