unknown top level operator when updating from a JSON REST Service

45 views
Skip to first unread message

Michael Rupprecht

unread,
Jan 13, 2015, 11:12:16 AM1/13/15
to reacti...@googlegroups.com
Hi

this appears to be a newbie question, I am trying to build a prototype of a CRUD reactive Mongo App using JSON Restful Webservices, I got the read, create and find thing done now I am struggeling with the update: Here is my code

object MYTest extends Controller with MongoController {


def collection: JSONCollection = db.collection[JSONCollection]("mytest")

...

def editTest = Action.async(parse.json) { request =>


request.body.validate[Test].map { test =>
collection.update(test._id, test).map { lastError =>

Ok(Json.obj("status" -> "OK"))
}
}.getOrElse(Future.successful(BadRequest("invalid json")))

}

 I have a valid JSON request using CURL or Postman :


{"_id":{"$oid":"54b51834d2856ce6006723be"},"title": "Test-33388","uri": "http://test-2","author": "tester-2","overallRating": 5,"summary": "very well done","testBody": "lorem ipsum","createDate": "13/01/2015 14:05:56","modifyDate": "13/01/2015 14:05:56"}

but I get an error 

		</style>
        </head>
        <body id="play-error-page">
            <h1>Execution exception</h1>
            <p id="detail" class="pre">[LastError: DatabaseException[&#x27;unknown top level operator: $oid&#x27; (code = 2)]]</p>
        </body>
    </html>


have no clue what I am doing wrong, can you help

Michael Rupprecht

unread,
Jan 14, 2015, 2:45:32 AM1/14/15
to reacti...@googlegroups.com
Ok it works when I cange the code to
 
  collection.save(test).map ...

according to the API doc this updates a document if it exists, or stores a new one if not ...
Reply all
Reply to author
Forward
0 new messages