0

我想在 mongo db 上设置一个更改流,但是有一个“无法解决重载方法订阅”,我无法找到问题的根源:

import org.mongodb.scala.{Document, MongoClient, MongoCollection, MongoDatabase}

object App {

  def main(args: Array[String]): Unit = {

      val mongoClient: MongoClient = MongoClient("mongodb://localhost")

      val database: MongoDatabase = mongoClient.getDatabase("db")

      val collection: MongoCollection[Document] = database.getCollection("col")
          collection.watch().subscribe(
            (doc: Document) => println(doc.toJson),
            (t: Throwable) => println(""),
              () => println()
          )
  }

}


libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "2.7.0"
4

1 回答 1

1

代替:

(doc: Document) => println(doc.toJson),

和:

(csd: ChangeStreamDocument[Document]) => println(csd.getFullDocument()),
于 2019-10-09T21:27:10.457 回答