What happens if the database is not available?

18 views
Skip to first unread message

Victor Caballero

unread,
Aug 4, 2017, 7:05:03 AM8/4/17
to mongodb-user
Hello,

I'm using the mongodb scala driver and I'm concerned about what happens if the database is not available or there is an error during a db operation. For example, I had an observable print something when there is an error (onError method) while inserting something with the db shutted down, but the method is never called. Shouldn't an exception be thrown at the time I get a MongoConnection? Or the onError method called when I send an operation to a shutted down db?

Wan Bachtiar

unread,
Aug 7, 2017, 4:20:46 AM8/7/17
to mongodb-user

For example, I had an observable print something when there is an error (onError method) while inserting something with the db shutted down, but the method is never called. Shouldn’t an exception be thrown at the time I get a MongoConnection? Or the onError method called when I send an operation to a shutted down db?

Hi Victor,

You can see examples of handling observables on MongoDB Scala Driver: observables

For example :


val insertObservable: Observable[Completed] = collection.insertOne(document)

insertObservable.subscribe(new Observer[Completed] {
    override def onNext(result: Completed): Unit = println(s"onNext: $result")
    override def onError(e: Throwable): Unit = println(s"onError: $e")
    override def onComplete(): Unit = println("onComplete")
})

If you still have further questions, could you please provide:

  • MongoDB Scala driver version
  • Snippet example of test code (containing the onError)
  • How do you emulate the shutting down after the connection is established ?

Regards,
Wan

Reply all
Reply to author
Forward
0 new messages