Reputation: 1
I need to listen to changes in MongoDb using KTOR.
I've tried Change Streams but can not implement it somehow. Could you please tell me other solutions or using Change Streams in a proper way. I don't want to use firebase anymore.
fun Application.launchChangeStreamWatcher(collection: MongoCollection<UserData>) {
launch {
val changeStream = collection.watch().iterator()
while (changeStream.hasNext()) {
val changeEvent = changeStream.next()
println("Received change event: $changeEvent")
}
}
fun Application.module() {
val collection by inject<MongoCollection<UserData>>()
launchChangeStreamWatcher(collection)
}
I get this error:
Exception in thread "main" org.koin.core.error.NoBeanDefFoundException: |- No definition found for class:'com.mongodb.client.MongoCollection'. Check your definitions!
Upvotes: 0
Views: 39