0
我用playframework與「org.mongodb.scala」 %%「蒙戈 - 斯卡拉驅動程序」%「1.0.1」,並有代碼:訂閱MONGO查詢不起作用
val collection = Mongo.db.getCollection("regionAuth")
def getRegions = {
val find: Observable[Document] = collection.find()
Logger.info("regions searching")
find.subscribe(new Observer[Document] {
override def onError(e: Throwable): Unit = Logger.error("regions error", e)
override def onSubscribe(subscription: Subscription): Unit = Logger.info("subscribed")
override def onComplete(): Unit = Logger.info("regions done")
override def onNext(result: Document): Unit = Logger.info("region accepted")
})
find.map { region =>
Logger.info("region accepted by map")
region
}
find.foreach(_ => Logger.info("region accepted by foreach"))
find.toFuture().onComplete {
case Success(r) => Logger.info("regions accepted as future seq " + r.size)
case Failure(e) => Logger.error("regions error as future", e)
}
find
}
它打印:
[信息]應用 - 區域搜索
[信息]應用 - 訂閱
[信息]應用 - 區域由foreac接受ħ
[信息]應用 - 通過的foreach接受區域
[信息]應用 - 通過的foreach接受區域
[信息]應用 - 區域接受爲未來SEQ 3
爲什麼訂閱的活動和地圖不工作?
或者你可以看看https://github.com/sgodbillon/reactivemongo-tailablecursor-demo – cchantep