zenexity/Play-ReactiveMongo — pull request #25 by FabienPennequin (2013-04-12 17:17:52+00:00)
Title: Fix for save method in JSONCollection

I had some issues with save() method in JSONCollection.

First, I get an infinite loop when I try to use it. This is because Play Writes return a JsValue and not a JsObject.

def save[T](doc: T, writeConcern: GetLastError = GetLastError())(implicit ec: ExecutionContext, writer: Writes[T]): Future[LastError] =
save(writer.writes(doc), writeConcern)

writer.writes(doc) returns an JsValue so we doen't call save(doc: JsObject, writeConcern: GetLastError) but we recall save\[T\](doc: T, writeConcern: GetLastError = GetLastError()) with T = JsValue. This is the infinite loop.

The second issue is encountered when I try to save an object which has an _id setted but which does not exist in mongodb. In this case, the object is not saved in the database.

I wrote some unit tests to reproduce these issues easily. I hope that will help you.

Please let me know if you need any further information.