2016-08-16 5 views
0

객체 배열을 저장하는 필드가 있습니다. 객체의 "id"값에 따라 객체의 "status"값을 수정하고 싶습니다. 몽고 DB의 PHP에서MongoDB - 배열의 객체 값을 수정하는 PHP

"authors" : [ 
     { 
      "id" : "18", 
      "first_name" : "Buddhika", 
      "last_name" : "Chathuranga", 
      "$$hashKey" : "object:35", 
      "status" : NumberLong(0) 
     }, 
     { 
      "id" : "3", // search for this number 
      "first_name" : "Pasindu", 
      "last_name" : "Priyanath", 
      "$$hashKey" : "object:43", 
      "status" : NumberLong(0) // modify this to 1 
     } 
    ], 

답변

2

우리는 배열 내에서 값을 업데이트하여 MongoDB에 위치 업데이 트를 활용할 수 있습니다.

Mongo Positional Update

아래 스크립트를 찾아주세요.

db.authors.update(
{"authors.id": "3"}, 
{ $set: { "authors.$.status" : NumberLong(1) }} 
) 
관련 문제