Hi all, I am trying to upload/insert json object/document from my front-end to store in Reactivemongo database(2.6) using Play/Scala framework(2.2.3). I have done the following trails, but I am failing to insert json document in the database.
class Application extends Controller with MongoController {
def jsinfocollection: JSONCollection = db.collection[JSONCollection]("mycollection")
def createJson = Action.async(parse.json) {
request =>
request.body.validate[JsValue].map {
println("calling: request.body.validate..!!")//coming message on Play console
jsoninfo =>
jsinfocollection.insert(jsoninfo).map {
println("calling: jsinfocollection.insert..!!")//coming message on Play console
lastError =>//Error is showing on Play console: play - Cannot invoke the action, eventually got an error: play.api.libs.json.JsResultException: JsResultException(errors:List((,List(ValidationError(errir.expected.jsobject,WrappedArray())))))]]
logger.debug("Json data inserted Successfully in Mongodb collection with LastError: $lastError")
Created("JsonInfo is Saved")
}
}.getOrElse(Future.successful(BadRequest("invalid json data")))
}
}
I created a collection,called: "mycollection" in Mongodb already like: >db.createCollection("mycollection")
{ "ok" : 1 }
but if I give: >db.mycollection.count() - is giving 0, otherwise if I give: db.mycollection.find() - is giving nothing
routes:
POST /createJson controllers.Application.createJson
Error:
play - Cannot invoke the action, eventually got an error: play.api.libs.json.JsResultException: JsResultException(errors:List((,List(ValidationError(errir.expected.jsobject,WrappedArray())))))]]
Please help me regarding this where and what I am doing wrong to upload/insert my json data into my required collection("mycollection") ?