Using ReactiveMongo, what would be the canonical way to find a single document using a query, delete this document and finally return it. I am also using the ReactiveMongo plugin for the Playframework. So far, I have come up with the following snippet:
def removeOne(query: JsObject)(implicit collection: JSONCollection): Future[Option[MyModel]] = {
collection.remove(query, firstMatchOnly = true).map(result => result match {
case success if result.ok => ???
case failure => throw new RuntimeException(failure.message)
})
}
The key question is a) Does the LastError
contain the single document and b) how can it be transformed to an Option
of MyModel
class.