ricsirigu/play26-swagger-reactivemongo

A way to remove collection.flatMap from every query

jyotman opened this issue · 1 comments

Hi, I was wondering if there's a way to resolve the collection Future. If in Todo.scala model, this -

def collection: Future[JSONCollection]

could be converted to -

def collection: JSONCollection

Then in every query we could remove the collection.flatMap.

Example -

def addTodo(todo: Todo): Future[WriteResult] = {
   collection.flatMap(_.insert(todo))
}

would become -

def addTodo(todo: Todo): Future[WriteResult] = {
  collection.insert(todo)
}

@jyotman yes you can but you shouldn't.
You can call .result on the future or use scala-async