val observer = new Observer[Document] {
override def onComplete {
//do something when completed
}
override def onError(e: Throwable) {
//do something when error
}
override def onNext(doc: Document) {
//do some when a record is found
// and keep your logic here maybe call another function passing 'doc'
}
}
collection.find(and(equal("name",name),equal("hobby",
hobby))).first().subscribe(observer)
或者
def doSome(doc:Document):Unit = {
//do something here with 'doc'
}
collection.find(and(equal("name",name),equal("hobby",
hobby))).first().subscribe(doSome)
您需要异步思考,例如带有回调的 javascript。
PS。我没有测试代码,它几乎是一个伪代码。
问候。