0

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"
SimbaPK
  • 566
  • 1
  • 7
  • 26

1 Answers1

1

replace:

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

with:

(csd: ChangeStreamDocument[Document]) => println(csd.getFullDocument()),
senjin.hajrulahovic
  • 2,961
  • 2
  • 17
  • 32