Play Reactivemongo只更新一个密钥

时间:2016-06-06 19:40:54

标签: post playback play-reactivemongo

我想只更新具有特定ID的文档中的一个键。

{
  "_id" : ObjectId("5755b80229d52a2e4bca4264"), 
  "ID" : 1, 
  "Entity_name" : "Basic Risk", 
  "Risk_name" : "Sample Risk", 
  "Parameters" : "ABCD", 
  "configurations" : "4564frgtretr56" 
}

我正在使用此代码执行相同的操作:

def update_configuration(id :Int) = Action.async(parse.json) {

request =>
  request.body.validate[RiskCriterias_F].map {
    user =>
      // find our user by first name and last name

      val nameSelector = Json.obj("ID" ->id)
      collection_criterias.update(nameSelector, user).map {
        lastError =>
          logger.debug(s"Successfully updated with LastError: $lastError")
          Created(s"Configuration for given ID is Updated")
      }
  }.getOrElse(Future.successful(BadRequest("invalidd jsoon")))
}

我正在使用curl发送POST请求,如下所示:

curl -H "Content-Type: application/json" -X POST -d '{ "configurations" : "4564frgtretr56" }' http://localhost:9000/risk_analyzer/risk_criterias/1/configurations

0 个答案:

没有答案