1장 Introdunction to MongoDB
Terminology
Rich Data Similar to Json
- BSON 저장 : BigDecimal 과 같은 Type 지원을 위해서 BJson 형태로 저장
ObjectId
- _id : 유니크 키. 클라이언트단 driver에서 생성하며 앞 4byte가 Timestmap
MongoDB Ecosystem
- MongoDB Server
- MongoDB Atlas
- MongoDB Serverless
- MongoDB Stitch : Serverless platform(앱개발자들이 서버없이 개발)
- MongoDB GUI
- MongoDB Compass
- MongoDB for Analytics
- MongoDB Charts
- MongoDB BI Connector : MySQL 쿼리로 조회 가능
2장 Scalability Though Replication and Sharding
Replication (Data Durability)
- 메모리에 있는 데이터를 CheckPoint(60sec, 2G) 마다 Disk에 저장
- 저널링(100MB, 50msec 마다) 으로 작게 저장
- OpLog 는 Disk 의 5%로 설정됨. OpLog 를 통해 복제
- 장애 시간이 길어서 OpLog로 복구가 안되면 Initial Sync 수행
- DIsk Free space는 40% 유지를 권고
Replica Set Repair
- Heatbeat And New Primary
- optime 비교
- latency (Network 부하)
- MongoDB 3.6 이상은 Driver 단에서 Retry Write 지원(1번)
Sharding
Reasons to Shard
- Performace
- Data locality
- Recovery Time Objective(RTO) : 분산되어 있어서 복구가 빠르다.
What is Sharding?
Picking A Shard Key
Q. Shrad Key는 반드시 지정해야 하나요?
A. 반드시 지정해야 함. 고르게 분포되는 키를 선정하거나 해시키로 분산. 액세스 패턴에 따라 키를 선정
Q. Sharding 은 나중에 결정해도 되는가? 어느 시점에 Sharding을 고려해야 하는가?
A. 데이터베이스 단위로 분산하고, 수평적인 Collection 단위 분산도 가능하다.
WorkingSet(메모리)와 Data Set(Disk) 을 보고 메모리 모니터링을 통해 Sharding 시점 판단
3장 스키마 디자인
Don't Over Design, Design For ...
- Performance
- Scalability
- Simplicity
Data Modeling - Time Series
- + Pre-Aggregation
- How will Data Scientists access the data?
MongoDB Schema Pattern 6가지
- Single View Pattern 의 좋은 사례가 뱅크 샐러드
4장 Indexing & Aggregation
Indexing
Index Types in MongoDb
- Single Field
- Compound Filed
- Multikey { "address.postal_code" : 1}
- Wildcard Index : 4.2 부터 지원
- Geospatial
- Text
- Hashed
Index Properties
- Unique
- Sparse
- Partial
- TTL : 설정한 시간 지나면 데이터 삭제
- Coverved
- Index build:
- Foreground : 인덱스 생성시 Collection 단위 locking 발생
- Backgorund
- Rolling
- Hybrid : 4.2 부터 지원
Aggregation Pipeline
Stages
Q. 조회 수를 구현하려면 어떻게 하는 것이 좋은가?
A. findAndModify 를 사용하면 증가된 Document 를 리턴 받을 수 있다.
Q. Slow Query는 어떻게 확인하나?
A. 로그로 확인
5장 MongoDB Atlas
Legacy Data Design
MongoDB Design
Article 을 스키마 디자인 할때 comment 는 Array로 저장한다.
Q. comment 는 별도 Collection 으로 저장해야 하는것이 아닌가?
A. comment Array는 최근 것만 저장하고 별도 Collection 으로 관리한다.
참고
https://docs.mongodb.com/manual/
https://www.mongodb.com/webinar/back-to-basics-webinar-series-2019
- https://www.mongodb.com/blog
- https://university.mongodb.com/
- Joe Dev On Tech - William Zola - The (Only) Three Reasons for Slow MongoDB Performance : https://www.youtube.com/watch?v=CJFXM6tZJqg
- https://github.com/mongodb-developer/back-to-basics-2019
https://data-flair.training/blogs/mongodb-tutorials-home/
'프로그래밍 > MongoDB' 카테고리의 다른 글
MongoDB Docker-compose Replica (0) | 2021.06.25 |
---|---|
[2월 25일] 온라인 세션 'MongoDB University 교육과정과 Certification에 대한 모든 것' (0) | 2021.02.16 |
M320 Data Modeling (0) | 2020.08.05 |
M001 MongoDB Basics (0) | 2020.08.05 |
대용량 데이터 처리를 위한 Real MongoDB (0) | 2020.08.05 |
신규 프로젝트를 위한 몽고 DB 도입 가이드 (0) | 2020.07.10 |