본문 바로가기

프로그래밍/MongoDB

몽고DB_BACK_TO_THE_BASIC

728x90
반응형

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 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://data-flair.training/blogs/mongodb-tutorials-home/

https://github.com/sjtuhjh/appdocs/blob/master/BooksAndPapers/GeneralPapers/Designing%20Data-Intensive%20Applications.pdf

MongoDB.local Seoul 2019 세미나 발표 자료 : https://view.highspot.com/viewer/5d8328ae8fd638057311282a?utm_campaign=Int_PAE_MongoDB.local%20Seoul_09_19_APAC_Presentation%20for%20Attendees&utm_medium=email&utm_source=Eloqua&utm_term=MongoDB%20Seoul%20%C3%AC%C2%9E%C2%90%C3%AB%C2%A3%C2%8C%C3%AC%C2%99%C2%80%20%C3%AD%C2%94%C2%84%C3%AB%C2%A0%C2%88%C3%AC%C2%A0%C2%A0%C3%AD%C2%85%C2%8C%C3%AC%C2%9D%C2%B4%C3%AC%C2%85%C2%98%C3%AC%C2%9D%C2%84%20%C3%AC%C2%82%C2%AC%C3%AC%C2%9A%C2%A9%C3%AD%C2%95%C2%98%C3%AC%C2%8B%C2%A4%20%C3%AC%C2%88%C2%98%20%C3%AC%C2%9E%C2%88%C3%AC%C2%8A%C2%B5%C3%AB%C2%8B%C2%88%C3%AB%C2%8B%C2%A4

 

728x90
반응형