我试图使用ReactiveMongo 0.12.7与Scala 2.11.8连接到MongoDB并遇到以下错误:
value connection is not a member of object reactivemongo.api.MongoDriver
相关性:
"org.reactivemongo" %% "reactivemongo" % "0.12.7"
和我的代码:
package com.some.package
// import scala.concurrent.{ExecutionContext, Future}
import reactivemongo.api.{DefaultDB, MongoConnection, MongoDriver}
import reactivemongo.bson.{BSONDocumentWriter, BSONDocumentReader, Macros, document}
import reactivemongo.core.nodeset.Authenticate
object MongoConfigReactive {
def getMongoCredentials(mongoDbName: String = "mydb",
mongoUsername: String = "username",
mongoPassword: String = "password"): List[Authenticate] = {
List(Authenticate(mongoDbName, mongoUsername, mongoPassword))
}
def getServerList(): List[String] = {
List("cluster0-shard-00-00-server.com:27017",
"cluster0-shard-00-01-server.com:27017",
"cluster0-shard-00-02-server.com:27017")
}
def getMongoConnection(): MongoConnection = {
val mongoDriver = MongoDriver
mongoDriver.connection(getServerList, authentications = getMongoCredentials())
}
}
我错过了什么吗?
答案 0 :(得分:0)
使用MongoDriver
随播广告对象时,您错过了括号:
val mongoDriver = MongoDriver()
或者,您可以直接创建MongoDriver
类的新实例:
val mongoDriver = new MongoDriver