Skip to content

Instantly share code, notes, and snippets.

@eduardorost
Last active September 1, 2019 02:18
Show Gist options
  • Save eduardorost/ecbf170f6f5bee6320bec6ba052e9dc2 to your computer and use it in GitHub Desktop.
Save eduardorost/ecbf170f6f5bee6320bec6ba052e9dc2 to your computer and use it in GitHub Desktop.
val client = MongoClient.apply("mongodb.uri")
val database = client.getDatabase("mongodb.database")
val collection = database.getCollection("mongodb.collection")
collection.watch()
.fullDocument(FullDocument.UPDATE_LOOKUP)
.subscribe(new Observer[ChangeStreamDocument[Document]] {
override def onNext(changeDocument: ChangeStreamDocument[Document]): Unit = process(changeDocument)
override def onError(e: Throwable): Unit = println(s"Error: $e")
override def onComplete(): Unit = println("Completed")
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment