reactivemongo - 值连接不是对象 reactivemongo.api.MongoDriver 的成员

reactivemongo - value connection is not a member of object reactivemongo.api.MongoDriver

我试图将 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())
    }
}

我错过了什么吗?

您在使用 MongoDriver 伴随对象时缺少括号:

val mongoDriver = MongoDriver()   

或者,您可以直接创建 MongoDriver class 的新实例:

val mongoDriver = new MongoDriver