2016-10-20 5 views
0

MongoDBからいくつかの値をロードしようとしていますが、コントローラアクションによってJSONとして提供しています。私はエラーが発生しています:オーバーロードされたメソッド値[subscribe]を適用できません

Overloaded method value [subscribe] cannot be applied to 
(
    org.mongodb.scala.bson.collection.immutable.Document => Unit, 
    Throwable => Unit, 
() => Unit 
) 

私にはすべてが動作しているように見えますが、ここで

は私のコントローラです:

package controllers 

import play.api.mvc._ 
import org.mongodb.scala.bson.collection.immutable.Document 
import data.NoteStore 

class NotesController extends Controller { 

    def index = Action { 
    NoteStore.find.subscribe(
     (note: Document) => println(note.toJson), 
     (error: Throwable) => println(s"Query failed: ${error.getMessage}"), 
    () => println("Done") 
    ) 
    } 
} 

そしてNoteStore

package data 

import org.mongodb.scala.model.Filters._ 

object NoteStore extends MongoStore { 
    def find = { 
    db("note-io").find 
    } 

    def findOne(id: Long) = { 
    db("note-io").find(equal("id", id)).first 
    } 
} 

私には私はsubscribeに渡されている引数が間違っているように見えますか?しかし、オンラインで見ていると、私はなぜそれが正しいのか分かりません。ドキュメントMongoCollection.findを見て

答えて

0

次のシグネチャを持つメソッドをサブスクライブしているObservable、間違ったパラメータを提供していることを明確に示して

def subscribe(observer: Observer[_ >: TResult]): Unit 

// and 

def subscribe(observer: com.mongodb.async.client.Observer[_ >: TResult]): Unit 

を返します。それにはObserverが必要でした。

collection.find().subscribe(
    new Observer[Document](){ 
     override def onSubscribe(subscription: Subscription): Unit = { 
     // probably some logging or something else that you want on subscription 
     } 

     override def onNext(document: Document): Unit = println(document.toJson()) 

     override def onError(e: Throwable): Unit = println(s"Error: $e") 

     override def onComplete(): Unit = println("Completed") 
    } 
) 
関連する問題