title: A ReactiveMongo pattern to return the created mongodb document in one RESTful request
body: <p><em>Environment: Play! 2.2.3, ReactiveMongo 0.10.0-SNAPSHOT</em></p>
  
  <p>Suppose I have a page with a list of documents (let's say "projects") and a button that pops up a modal dialogue with fields to be filled in. Upon pressing the OK button the page sends a request with JSON body to the backend:</p>
  
  <pre><code>{
      name: "Awesome Project", 
      url: "https://github.com/ab/cd", 
      repository: "git@github.com/ab/cd.git", 
      script: "empty"
  }
  </code></pre>
  
  <p>The backend routes the request to the <code>Action</code> defined like this:</p>
  
  <pre><code>  def projectsCollection: JSONCollection = db.collection[JSONCollection]("projects")
  
    def create = Action.async(parse.json) { request =&gt;
      projectsCollection.insert(request.body) map {
        case LastError(true,_,_,_,Some(doc),_,_) =&gt;  Created(JsObject(List(
          "result" -&gt; JsString("OK") ,
          "doc" -&gt; BSONFormats.toJSON(doc)
        )))
        case LastError(false, err, code, msg, _, _, _) =&gt; NotAcceptable(JsObject(List(
          "result" -&gt; JsString("ERROR"),
          "error" -&gt; JsString(err.getOrElse("unknown")),
          "code" -&gt; JsNumber(code.getOrElse[Int](0)),
          "msg" -&gt; JsString(msg.getOrElse("no messsage"))
        )))
      }
    }
  </code></pre>
  
  <p>The <code>LastError</code> case class has a parameter <code>originalDocument: Option[BSONDocument]</code> which is returned in the request response body, but it isn't the document I expected. I want the document with the <code>BSONObjectID</code> filled or at least the <code>_id</code> itself.</p>
  
  <p>Trying to retrieve the freshly created document led me into a dead end, because everything is wrapped into <code>Future</code>.</p>
  
  <p>How to write elegant code that does the task?</p>