https://www.mongodb.com/docs/v4.4/reference/update-methods/
Update Methods — MongoDB Manual
Docs Home → MongoDB Manual MongoDB provides the following methods for updating documents in a collection:Updates at most a single document that match a specified filter even though multiple documents may match the specified filter.Update all documents th
www.mongodb.com
단일 문서 수정 ( updateOne(필터, 업데이트), $set )
db.컬렉션.updateOne(필터, 업데이트)
>db.inventory.updateOne({item:’paper’},{$set:{qty:200, “size.uom”:”cm”}})
값을 감소시키는 경우
>db.inventory.updateOne({item:’paper’},{$inc:{qty:-50}}) // -50
혼합
> db.inventory.updateOne({item:'paper'},{$set:{status:'F'}, $inc:{qty:50}})
멀티 문서 수정 ( updateMany(필터, 업데이트), $set )
db.컬렉션.updateMany(필터, 업데이트)
>db.inventory.updateMany({qty:{$lt:50}}, {$set:{status:'F'}})
'NoSQL > MongoDB' 카테고리의 다른 글
delete document : 문서 삭제 (0) | 2023.10.06 |
---|---|
insert document : 문서 저장 (0) | 2023.10.05 |
limit (n), skip(n), sort({key:1}) 1: 오름차순, -1: 내림차순 (1) | 2023.10.05 |
embedded document (중첩 JSON) (0) | 2023.10.05 |
배열 조회 (0) | 2023.10.02 |