Transform a MongoDb parent reference tree into a deep nested tree Given a mongodb collection that stores trees as nodes with parent references this methods returns a deep nested tree where every child nodes are stored in a property childs[Seq]

  def getTree(rootId: BSONObjectID): Future[CategoryTreeNode] = {

    def collect(parent: CategoryTreeNode): Future[CategoryTreeNode] = {

      // Query the database - returns a Future[Seq[CategoryTreeNode]]
      getChilds(parent._id.get).map {

        // Seq[CategoryTreeNode]
        childs =&gt;
          Future.sequence(
            childs.map(child =&gt; collect(child)) // Recursion
          ).map(childSeq =&gt; parent.copy(childs = Some(childSeq)))

      }.flatMap(x =&gt; x).map(y =&gt; y) 

    }

    // Find the root node and start the recursion
    findOne[CategoryTreeNode](Json.obj("_id" -&gt; rootId)).map(maybeNode =&gt; maybeNode match {
      case None =&gt; throw new RuntimeException("Current node not found by id!")
      case Some(node) =&gt; collect(node)
    }).flatMap(x =&gt; x)

  }
flatMap (x =&gt; x) would probably better be written as flatten.
map (x =&gt; x) is essentially a no-op, and could be removed.
map ( ... ) flatten is equivalent to flatMap (...)
It doesn't seem useful to put a type into a comment – you can specify the type for parameters of lambdas as well:

{ (childs: Seq[CategoryTreeNode]) =&gt; ...


However, this style is generally discouraged. It would be more useful to store the future from the DB in a variable which gets typed explicitly.
Higher-order method like map should not be invoked with a leading .: do collection map (x =&gt; ...) instead of collection.map(x =&gt; ...) (source).
(foo =&gt; foo match { ... }) can be simplified to (_ match { ... })
(child =&gt; collect(child)) can be simplified to (collect(_)) or even just collect


Together, I'd clean up your code to this:

def getTree(rootId: BSONObjectID): Future[CategoryTreeNode] = {
  def collect(parent: CategoryTreeNode): Future[CategoryTreeNode] = {
    // Query the database
    val ourChilds: Future[Seq[CategoryTreeNode]] = getChilds(parent._id.get)
    ourChilds flatMap { childs =&gt;
      Future.sequence(childs map collect) map { childSeq =&gt;
        parent.copy(childs = Some(childSeq))
      }
    }
  }

  // Find the root node and start the recursion
  findOne[CategoryTreeNode](Json.obj("_id" -&gt; rootId)) flatMap (_ match {
    case None =&gt; throw new RuntimeException("Current node not found by id!")
    case Some(node) =&gt; collect(node)
  })
}