'usa'를 'united + states'로 바꾸려는 'locations'컬렉션이 있습니다.MongoDB 값 일치로 배열 요소 업데이트
내가 트릭 했어야 다음 MongoDB의 쿼리 실행> db.locations.find({'country':'usa'})
{ "_id" : "boston", "country" : [ "usa" ], "server" : "", "ts" : 1369642586.077319, "type" : [ "city" ] }
{ "_id" : "chicago", "country" : [ "usa" ], "server" : "", "ts" : 1369642589.226037, "type" : [ "city" ] }
{ "_id" : "las+vegas", "country" : [ "usa" ], "server" : "", "ts" : 1369642591.688284, "type" : [ "city" ] }
{ "_id" : "los+angeles", "country" : [ "usa" ], "server" : "", "ts" : 1369642601.672113, "type" : [ "city" ] }
{ "_id" : "miami", "country" : [ "usa" ], "server" : "", "ts" : 1369642606.281971, "type" : [ "city" ] }
{ "_id" : "new+york", "country" : [ "usa" ], "server" : "", "ts" : 1369642611.884712, "type" : [ "city" ] }
{ "_id" : "portland", "country" : [ "usa" ], "server" : "", "ts" : 1369642615.59296, "type" : [ "city" ] }
{ "_id" : "san+francisco", "country" : [ "usa" ], "server" : "2", "ts" : 1369642619.255885, "type" : [ "city" ] }
{ "_id" : "san+jose", "country" : [ "usa" ], "server" : "", "ts" : 1369642622.74329, "type" : [ "city" ] }
{ "_id" : "seattle", "country" : [ "usa" ], "server" : "", "ts" : 1369642625.195549, "type" : [ "city" ] }
{ "_id" : "washington+dc", "country" : [ "usa" ], "server" : "", "ts" : 1369642628.37334, "type" : [ "city" ] }
{ "_id" : "cleveland", "country" : [ "usa" ], "server" : "2", "ts" : 1369642634.523065, "type" : [ "city" ] }
{ "_id" : "columbus", "country" : [ "usa" ], "server" : "2", "ts" : 1369642636.874618, "type" : [ "city" ] }
{ "_id" : "dallas", "country" : [ "usa" ], "server" : "2", "ts" : 1369642639.080141, "type" : [ "city" ] }
{ "_id" : "denver", "country" : [ "usa" ], "server" : "2", "ts" : 1369642642.236581, "type" : [ "city" ] }
{ "_id" : "houston", "country" : [ "usa" ], "server" : "2", "ts" : 1369642644.783804, "type" : [ "city" ] }
{ "_id" : "minneapolis", "country" : [ "usa" ], "server" : "2", "ts" : 1369642647.153817, "type" : [ "city" ] }
{ "_id" : "nashville", "country" : [ "usa" ], "server" : "2", "ts" : 1369642650.497276, "type" : [ "city" ] }
{ "_id" : "new+orleans", "country" : [ "usa" ], "server" : "2", "ts" : 1369642653.584663, "type" : [ "city" ] }
{ "_id" : "philadelphia", "country" : [ "usa" ], "server" : "2", "ts" : 1369642656.524054, "type" : [ "city" ] }
:
db.locations.update({'country':'usa'}, {'$set': {'country.$': 'united+states'}}, multi=true)
그러나이 달성되지 않습니다 원하는 영향을 미칠 스 컬렉션 DB의 현재 상태는 다음과 같습니다 문서에는 여전히 '미국'대신 '미국'이 있습니다. 여러 배열 요소를 업데이트
이
교차 확인 했습니까? 기본적으로 업데이트는 하나의 문서 만 업데이트하며 일치하는 모든 문서화는 업데이트하지 않습니다. 업데이트가 작동했을 수도 있습니다. db.locations.count ({ 'country': 'usa'})가 업데이트 전과 후에 동일한 값을 반환하는지 확인하십시오. – gkamal