티스토리 뷰

NoSQL/MongoDB

update document : 문서 수정

xoo | 수진 2023. 10. 6. 13:31

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
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함