-
Mongodb add key-value pair to object스터디노트/DB 2022. 11. 8. 10:34
타입이 Object인 도큐먼트에 key-value 쌍인 데이터를 업데이트 하기
const updatedUser = await db.collection('users').updateOne( { name: '태호', }, { $set: { [`personalInfo.${age}${gender}`]: personalInfo, // template literal을 []로 감싸서 작성 }, }, { upsert: true, } );
참고자료
'스터디노트 > DB' 카테고리의 다른 글
MongoDB findOne() without _id & MongoDB에서 find와 aggregate 성능 차이 (0) 2023.01.26 How to push or pull item from an array in Mongoose (0) 2022.12.06 MongoDB Query for documents array size is greater than (0) 2022.09.20 필드가 배열인 경우 MongoDB update하기 (0) 2022.07.26 MongoDB 사칙연산 쿼리 (0) 2022.07.04