IT/MongoDB

$rename (Update Operators/Field Update Operators)

KeepGooing 2021. 4. 12. 19:58
반응형
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"}]}

    );

 

반응형