2

I'm using play framework and mongo scala driver to set a database up, I need to parse the result of a query to Json to send it to the front-end:

def getAllProcess(userId: String) = {
    getCollection(COMPANY_FORM).find(equal("userId", userId)).subscribe(new Observer[Document] {
      override def onError(e: Throwable): Unit = println(e)

      override def onComplete(): Unit = println("Complete")

      override def onNext(result: Document): Unit = println(result)
    })
  }

How to parse its result ?

Azoulay Jason
  • 2,787
  • 5
  • 21
  • 46
  • You can start by converting the result of the query to a Future so you can map the data and pass it as need be. Subscribers aren't very useful in idiomatic Scala – Kevin Hoerr Apr 23 '18 at 13:29
  • It's impossible in this case to return a future – Azoulay Jason Apr 23 '18 at 13:58
  • Try `getCollection(COMPANY_FORM).find(equal("userId", userId)).toFuture()`. Then you can either pipe it into something that takes Futures or call Await.result() and get the result to pass it to the play framework. I'm not familiar with how the play framework works – Kevin Hoerr Apr 23 '18 at 14:06

0 Answers0