반응형
db.getCollection('intent_service_2_origin').updateMany({}, {$rename:{"intent" : "case"}})
필드명 intent를 case로 일괄 수정
db.getCollection('intent_service_2_origin').updateMany({}, {$rename:{"typeArray.$[arrPosition].reqType" : "type"}}, {arrayFilters:[{"arrPosition.reqType" : "type1"}]});
"The source field for $rename may not be dynamic: typeArray.$[arrPosition].reqType
불가!
array 안의 필드명은 아직 연산자로 지원하지 않는다.
기존의 값을 불러와 재저장하고 그 이후 기존의 데이터를 지우는 방식으로 대부분 진행하는 듯 하다.
참고 https://stackoverflow.com/questions/9122966/mongodb-rename-database-field-within-array
MongoDB rename database field within array
I need to rename indentifier in this: { "general" : { "files" : { "file" : [ { "version" : { "software_program" : "MonkeyPlus", "indentifie...
stackoverflow.com
$set으로 생성
db.getCollection('intent_service_2_copy_copy').updateMany(
{},
[{$set:{"typeArray.type" : 1}}]
);
$unset으로 지움
db.getCollection('intent_service_2_copy_copy').updateMany(
{"typeArray.reqType": {$exists:true}},
{$unset:{"typeArray.$[ar].reqType" : 1}},
{arrayFilters:[{'ar.reqType' : "type1"}]}
);
반응형
'IT > MongoDB' 카테고리의 다른 글
mongodb 중복 필드인 경우 find할 때 모두 조회 안되는 경 (0) | 2021.05.21 |
---|---|
arrayFilters (0) | 2021.04.13 |
$eq 와 $ne (Operatros/Query and Projection Operators/Comparision Query Operators) (0) | 2021.04.12 |
$unset (Field Update Operators) (0) | 2021.04.12 |
JSON.parse() 활용하여 몽고디비 필드 동적 생성 (0) | 2021.04.11 |