Home:ALL Converter>mongodb change stream cannot resolve subscribe

mongodb change stream cannot resolve subscribe

Ask Time:2019-10-10T03:33:54         Author:SimbaPK

Json Formatter

i want to set a change stream on mongo db, But there is a "Cannot resolve overloaded method subscribe" and I'm not able to find the source of the problem :

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"

Author:SimbaPK,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58311099/mongodb-change-stream-cannot-resolve-subscribe
yy