我想用scala连接mongodb,但出现错误:
No server chosen by com.mongodb.async.client.ClientSessionHelper$1@8c3b9d from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=10.74.155.54:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
以下是一些版本信息:
-MongoDB:4.0.3版
-斯卡拉:2.11.12
这是我的
build.sbt
文件
libraryDependencies ++= Seq(
"org.mongodb" % "bson" % "3.8.2",
"org.mongodb" % "mongodb-driver-core" % "3.8.2",
"org.mongodb" % "mongodb-driver-async" % "3.8.2",
"org.mongodb.scala" %% "mongo-scala-driver" % "2.4.2",
"org.mongodb.scala" % "mongo-scala-bson_2.11" % "2.4.2"
)
我这样编码:
val mongoClient: MongoClient = MongoClient("mongodb://xxxx/mydb")
val database: MongoDatabase = mongoClient.getDatabase("mydb")
val collection: MongoCollection[Document] = database.getCollection("test")
我只想连接一个
standalone mongod
,你能帮我吗?
谢谢!