티스토리 뷰

NoSQL/MongoDB

insert document : 문서 저장

xoo | 수진 2023. 10. 5. 14:25

https://www.mongodb.com/docs/v4.4/reference/insert-methods

 

Insert Methods — MongoDB Manual

Docs Home → MongoDB Manual MongoDB provides the following methods for inserting documents into a collection:If you use MongoDB Atlas, the fully managed service for MongoDB deployments in the cloud, you can use these methods to insert documents after you

www.mongodb.com

 

 

_id  속성을 명시하지 않으면 자동으로 생성된다. ( pk 역할, ObjectId 타입이고 24글자로 구성됨 )

 

 


 

 

단일 문서 저장 ( insertOne(문서) )

db.컬렉션.insertOne(문서)

> db.inventory.insertOne( { item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" } } )

 

 

> db.inventory.find()             //조회해서 내용 확인

 

 


 

 

멀티 문서 저장 ( insertMany([문서1,문서2,…]) )

db.컬렉션.insertMany([문서1,문서2,...])

> db.inventory.insertMany([
{ item: "journal", qty: 25, tags: ["blank", "red"], size: { h: 14, w: 21, uom: "cm" } },
{ item: "mat", qty: 85, tags: ["gray"], size: { h: 27.9, w: 35.5, uom: "cm" } },
{ item: "mousepad", qty: 25, tags: ["gel", "blue"], size: { h: 19, w: 22.85, uom: "cm" } }
])

 

 

> db.inventory.find()             //조회해서 내용 확인

'NoSQL > MongoDB' 카테고리의 다른 글

delete document : 문서 삭제  (0) 2023.10.06
update document : 문서 수정  (0) 2023.10.06
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
글 보관함