MongoDB 이해하기

선협 이
선협 이Developer at 트러스트어스
이해하기
2021. 02. 15
이선협
오늘의 목표
MongoDB 분산 시스템 모델링 패턴
MongoDB 분산 시스템 모델링 패턴
오늘의 목표
NoSQL이란?
Not Only SQL
관계형 DB가 아닌 DB
•분산 시스템을 위해 탄생
•RDBMS에서 하기 힘든 것을 지원
•Schema-less
•MongoDB, Redis, HBase...
NoSQL
RDBMS vs NoSQL
RDBMS NoSQL
장점
• 데이터의 무결성을 보장한다.

• 정규화를 통해 필요한 부분만 수정이 가능하
다.

• 기본적으로 일관성을 유지한다.
• 스키마가 없어 유연하게 데이터를 저장할 수
있다.

• 분산 시스템에서 가용성이 뛰어나다.

• 읽기 성능이 뛰어나다.

• 수직, 수평 확장이 가능하다.
단점
• 관계가 많을수록 복잡한 쿼리를 사용해야한다.

• 수평적 확장이 어렵다. 따라서 성장 한계가 존
재한다.
• 관계가 없기 때문에 사실상 정규화가 불가능
하다. 때문에 연관된 데이터가 있을 경우 여러
컬렉션에서 데이터를 수정해야한다.

• 무결성이 보장되지 않아 사용자의 실수가 그
대로 반영될 수 있다.
•Document
•BASE
•Open Source
MongoDB
MongoDB
MongoDB - Document
Document의 구조
MongoDB - Document
Document 스키마 타입
MongoDB - Document
https://developer.mongodb.com/quickstart/bson-data-types-objectid
ObjectId
MongoDB - Document
조작 방법
MongoDB - BASE
•Basically Available
•Soft state
•Eventually consistent
•ACID를 포기하고 성능과 가용성을 우선
MongoDB - BASE
Basically Available
•기본적으로 언제든지 사용할 수 있다.
•가용성이 필요하다는 의미
MongoDB - BASE
Soft state
•외부의 개입이 없어도 정보가 변경될 수 있다.
•네트워크 파티션 등 문제가 발생되어 일관성이 유지되지
않는 경우 일관성을 위해 데이터를 자동으로 수정한다.
MongoDB - BASE
Eventually consistent
•일시적으로 일관적이지 않은 상태가 되어도 일정 시간 후
일관적인 상태가 되어야한다.
•장애 발생시 일관성을 유지를 위한 이벤트를 발생시킨다.
MongoDB - BASE
MongoDB - ACID?
•Single-Document Transaction
•Multi-Document Transaction (4.0)
•Shard Cluster Transaction (4.2)
MongoDB 분산 시스템 모델링 패턴
오늘의 목표
🤔
대규모 데이터를 처리해야하는데

RDBMS는 성장 한계가 있구나

일관성과 무결성을 버리고 더 빠른 읽기 성능과 

수평 확장이 가능한 DB가 필요해
MongoDB 이해하기
•Consistency (일관성)
•Availability (가용성)
•Partition tolerance (분할내성)
CAP Theorem
•모든 노드가 같은 시간에 같은 데이터를 볼 수 있다.
Consistency
•모든 요청에 성공 혹은 실패 결과를 반환 할 수 있다.
Availability
•통신에 실패해도 시스템이 계속 동작해야한다.
Partition tolerance
MongoDB는 일관성과
분할내성을 지닌 데이터베이스다
음…………………
그런데 CA가 가능한가요?
•완벽한 CP, AP 시스템은 구리다.
•CA는 네트워크 장애가 절대 발생하지 않아야
하기 때문에 사실상 불가능하다.
•따라서 P는 무조건 인정하고 들어가야한다.
•대부분의 분산 시스템은 상황에 따라 일관성과
가용성의 우선순위를 다르게 설정한다.
CAP 이론의 한계
MongoDB 이해하기
PACELC Theorem
MongoDB 이해하기
P-S-S
P-S-A
MongoDB 분산 시스템 모델링 패턴
오늘의 목표
Not Only SQL
관계형 DB가 아닌 DB
•Parent References
•Child References
•Array of Ancestors
•Materialized Paths
•Nested Sets
Model Tree Structures
Model Tree Structures
Parent References
Model Tree Structures
Child References
Model Tree Structures
Array of Ancestors
Model Tree Structures
Materialized Paths
Model Tree Structures
Nested Sets
•1:1
•1:N
•N:M
Model Relationships
Model Relationships
Link vs Embed
Model Relationships
1:1
•Document의 크기가 엄청 크지 않다면
Sub Document로 Embed하는 것이 좋다.
•너무 크다면 Link 관계로 유지하고 필요한 경우
Setset 패턴을 사용한다.
Model Relationships
1:N
•Embed vs Link를 참고하여 선택한다.
•필요한 경우 Setset 패턴을 사용한다.
Model Relationships
N:M
•Array를 사용하여 Link할 수 있다.
•단방향, 양방향을 정한다.
•어떤 Collection에서 쿼리가 자주 발생하는지에 따라
모델링 해야한다.
•Attribute
•Extended Reference
•Subset
•Computed
•Bucket
•Schema Versioning
Modeling Patterns
Modeling Patterns
Attribute
•동일한 필드를 묶는 패턴
•인덱싱 수를 줄일 수 있다.
Modeling Patterns
Attribute
Modeling Patterns
Extended Reference
•관계가 있는 Document에서 자주 사용되는
데이터를 저장해두는 패턴
•쿼리 호출 횟수를 줄일 수 있다.
•데이터 수정이 있는 경우 양쪽을 모두 수정해야한다.
Modeling Patterns
Extended Reference
Modeling Patterns
Subset
•관계가 있는 Document 사이에 자주 쓰이는 데이터를
부분적으로 Embed하는 패턴
•쿼리 호출 횟수를 줄일 수 있다.
•데이터 수정이 있는 경우 양쪽을 모두 수정해야한다.
Modeling Patterns
Subset
Modeling Patterns
Computed
•Document write시 통계값을 저장하는 패턴
•read 성능 낭비를 막을 수 있다.
•오차가 있을 수 있다.
Modeling Patterns
Computed
Modeling Patterns
Bucket
•하나의 필드를 기준으로 Document들을 묶는 패턴
•실시간으로 데이터가 들어오는 시계열 데이터에 적합
•필드 추가, 인덱스 크기 절약, 쿼리 단순화에 좋다
•최대 BSON 사이즈를 넘지 않도록 조심해야한다.
Modeling Patterns
Bucket
Modeling Patterns
Schema Versioning
•Document에 버전 정보를 기록하는 패턴
•서비스가 발전하면서 스키마가 변경될 수 있다.
이 때 Schema Versioning 패턴을 사용하면 기존
데이터를 수정하지 않아도 괜찮다.
•Document가 너무 많은 경우 유용하다.
Modeling Patterns
Schema Versioning
MongoDB 이해하기
1 of 62

Recommended

NoSQL - Not Only SQL by
NoSQL - Not Only SQLNoSQL - Not Only SQL
NoSQL - Not Only SQLEasyData
493 views7 slides
Happiest Minds is Hiring! by
Happiest Minds is Hiring!Happiest Minds is Hiring!
Happiest Minds is Hiring!Ashok K DL
245 views2 slides
Introduction to NoSQL by
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQLDimitar Danailov
1.3K views51 slides
Mongo db groundup-0-nosql-intro-syedawasekhirni by
Mongo db groundup-0-nosql-intro-syedawasekhirniMongo db groundup-0-nosql-intro-syedawasekhirni
Mongo db groundup-0-nosql-intro-syedawasekhirniDr. Awase Khirni Syed
729 views61 slides
NoSql Brownbag by
NoSql BrownbagNoSql Brownbag
NoSql BrownbagSandeep Kumar
472 views14 slides
Relational and non relational database 7 by
Relational and non relational database 7Relational and non relational database 7
Relational and non relational database 7abdulrahmanhelan
230 views40 slides

More Related Content

Similar to MongoDB 이해하기

SQL vs NoSQL Data Modeling.pptx by
SQL vs NoSQL Data Modeling.pptxSQL vs NoSQL Data Modeling.pptx
SQL vs NoSQL Data Modeling.pptxGarimaHasija1
15 views24 slides
Mongo db model relationships with documents by
Mongo db model relationships with documentsMongo db model relationships with documents
Mongo db model relationships with documentsDr. Awase Khirni Syed
1.1K views183 slides
Why no sql ? Why Couchbase ? by
Why no sql ? Why Couchbase ?Why no sql ? Why Couchbase ?
Why no sql ? Why Couchbase ?Ahmed Rashwan
1K views23 slides
Nosql primer by
Nosql primerNosql primer
Nosql primerSeshu Kumar Loka
113 views9 slides
Introduction to NoSQL by
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQLDr-Dipali Meher
2.2K views72 slides
NoSql evaluation by
NoSql evaluationNoSql evaluation
NoSql evaluationKarthik Mohan
237 views23 slides

Similar to MongoDB 이해하기(20)

SQL vs NoSQL Data Modeling.pptx by GarimaHasija1
SQL vs NoSQL Data Modeling.pptxSQL vs NoSQL Data Modeling.pptx
SQL vs NoSQL Data Modeling.pptx
GarimaHasija115 views
Why no sql ? Why Couchbase ? by Ahmed Rashwan
Why no sql ? Why Couchbase ?Why no sql ? Why Couchbase ?
Why no sql ? Why Couchbase ?
Ahmed Rashwan1K views
The Rise of NoSQL and Polyglot Persistence by Abdelmonaim Remani
The Rise of NoSQL and Polyglot PersistenceThe Rise of NoSQL and Polyglot Persistence
The Rise of NoSQL and Polyglot Persistence
Abdelmonaim Remani19.6K views
RELATIONAL MODEL OF DATABASES AND OTHER CONCEPTS OF DATABASES​ by EdwinJacob5
RELATIONAL MODEL OF DATABASES AND OTHER CONCEPTS OF DATABASES​RELATIONAL MODEL OF DATABASES AND OTHER CONCEPTS OF DATABASES​
RELATIONAL MODEL OF DATABASES AND OTHER CONCEPTS OF DATABASES​
EdwinJacob587 views
introduction to NOSQL Database by nehabsairam
introduction to NOSQL Databaseintroduction to NOSQL Database
introduction to NOSQL Database
nehabsairam3.5K views
NoSQLDatabases by Adi Challa
NoSQLDatabasesNoSQLDatabases
NoSQLDatabases
Adi Challa395 views
Selecting the right database type for your knowledge management needs. by Synaptica, LLC
Selecting the right database type for your knowledge management needs.Selecting the right database type for your knowledge management needs.
Selecting the right database type for your knowledge management needs.
Synaptica, LLC89 views
DIFFERENT MODELS IN DBMS.pptx by Kavya990096
DIFFERENT MODELS IN DBMS.pptxDIFFERENT MODELS IN DBMS.pptx
DIFFERENT MODELS IN DBMS.pptx
Kavya99009617 views
6 Data Modeling for NoSQL 2/2 by Fabio Fumarola
6 Data Modeling for NoSQL 2/26 Data Modeling for NoSQL 2/2
6 Data Modeling for NoSQL 2/2
Fabio Fumarola12.1K views
Sql vs NO-SQL database differences explained by Satya Pal
Sql vs NO-SQL database differences explainedSql vs NO-SQL database differences explained
Sql vs NO-SQL database differences explained
Satya Pal6.4K views
Database awareness by kloia
Database awarenessDatabase awareness
Database awareness
kloia116 views

More from 선협 이

웹 개발을 위해 꼭 알아야하는 보안 공격 by
웹 개발을 위해 꼭 알아야하는 보안 공격웹 개발을 위해 꼭 알아야하는 보안 공격
웹 개발을 위해 꼭 알아야하는 보안 공격선협 이
7.4K views46 slides
Deep dive into Vue.js by
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js선협 이
2.4K views62 slides
오픈소스를 여행하는 히치하이커를 위한 안내서 - 자막 by
오픈소스를 여행하는 히치하이커를 위한 안내서 - 자막오픈소스를 여행하는 히치하이커를 위한 안내서 - 자막
오픈소스를 여행하는 히치하이커를 위한 안내서 - 자막선협 이
880 views83 slides
Metal 기반 특별한 UI/UX 제공하기 - Let'Swift 2017 by
Metal 기반 특별한 UI/UX 제공하기 - Let'Swift 2017Metal 기반 특별한 UI/UX 제공하기 - Let'Swift 2017
Metal 기반 특별한 UI/UX 제공하기 - Let'Swift 2017선협 이
1.3K views67 slides
Vue.js와 Reactive Programming 자막 :: Vuetiful Korea 2nd by
Vue.js와 Reactive Programming 자막 :: Vuetiful Korea 2ndVue.js와 Reactive Programming 자막 :: Vuetiful Korea 2nd
Vue.js와 Reactive Programming 자막 :: Vuetiful Korea 2nd선협 이
6.1K views126 slides
Reactive Programming With Swift by
Reactive Programming With SwiftReactive Programming With Swift
Reactive Programming With Swift선협 이
5.6K views98 slides

More from 선협 이(16)

웹 개발을 위해 꼭 알아야하는 보안 공격 by 선협 이
웹 개발을 위해 꼭 알아야하는 보안 공격웹 개발을 위해 꼭 알아야하는 보안 공격
웹 개발을 위해 꼭 알아야하는 보안 공격
선협 이7.4K views
Deep dive into Vue.js by 선협 이
Deep dive into Vue.jsDeep dive into Vue.js
Deep dive into Vue.js
선협 이2.4K views
오픈소스를 여행하는 히치하이커를 위한 안내서 - 자막 by 선협 이
오픈소스를 여행하는 히치하이커를 위한 안내서 - 자막오픈소스를 여행하는 히치하이커를 위한 안내서 - 자막
오픈소스를 여행하는 히치하이커를 위한 안내서 - 자막
선협 이880 views
Metal 기반 특별한 UI/UX 제공하기 - Let'Swift 2017 by 선협 이
Metal 기반 특별한 UI/UX 제공하기 - Let'Swift 2017Metal 기반 특별한 UI/UX 제공하기 - Let'Swift 2017
Metal 기반 특별한 UI/UX 제공하기 - Let'Swift 2017
선협 이1.3K views
Vue.js와 Reactive Programming 자막 :: Vuetiful Korea 2nd by 선협 이
Vue.js와 Reactive Programming 자막 :: Vuetiful Korea 2ndVue.js와 Reactive Programming 자막 :: Vuetiful Korea 2nd
Vue.js와 Reactive Programming 자막 :: Vuetiful Korea 2nd
선협 이6.1K views
Reactive Programming With Swift by 선협 이
Reactive Programming With SwiftReactive Programming With Swift
Reactive Programming With Swift
선협 이5.6K views
Tour of Vue.js by 선협 이
Tour of Vue.jsTour of Vue.js
Tour of Vue.js
선협 이18.1K views
Functional Reactive Programming With RxSwift by 선협 이
Functional Reactive Programming With RxSwiftFunctional Reactive Programming With RxSwift
Functional Reactive Programming With RxSwift
선협 이28.6K views
파크히어 Realm 사용 사례 by 선협 이
파크히어 Realm 사용 사례파크히어 Realm 사용 사례
파크히어 Realm 사용 사례
선협 이3.7K views
왜 Swift를 해야할까요? by 선협 이
왜 Swift를 해야할까요?왜 Swift를 해야할까요?
왜 Swift를 해야할까요?
선협 이4.6K views
C++ 코드 품질 관리 비법 by 선협 이
C++ 코드 품질 관리 비법C++ 코드 품질 관리 비법
C++ 코드 품질 관리 비법
선협 이27.1K views
C++과 Lua script연동 by 선협 이
C++과 Lua script연동C++과 Lua script연동
C++과 Lua script연동
선협 이21.8K views
MSBuild + Git + Jenkins by 선협 이
MSBuild + Git + JenkinsMSBuild + Git + Jenkins
MSBuild + Git + Jenkins
선협 이15.3K views
Post Effect 테스트 by 선협 이
Post Effect 테스트Post Effect 테스트
Post Effect 테스트
선협 이3.2K views
C++과 TDD by 선협 이
C++과 TDDC++과 TDD
C++과 TDD
선협 이7.5K views

Recently uploaded

STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdfDr. Jimmy Schwarzkopf
24 views29 slides
PRODUCT PRESENTATION.pptx by
PRODUCT PRESENTATION.pptxPRODUCT PRESENTATION.pptx
PRODUCT PRESENTATION.pptxangelicacueva6
18 views1 slide
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
23 views15 slides
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc
72 views29 slides
Unit 1_Lecture 2_Physical Design of IoT.pdf by
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdfStephenTec
15 views36 slides
SUPPLIER SOURCING.pptx by
SUPPLIER SOURCING.pptxSUPPLIER SOURCING.pptx
SUPPLIER SOURCING.pptxangelicacueva6
20 views1 slide

Recently uploaded(20)

STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab23 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc72 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec15 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 views
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe by Simone Puorto
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
Simone Puorto13 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
The Forbidden VPN Secrets.pdf by Mariam Shaba
The Forbidden VPN Secrets.pdfThe Forbidden VPN Secrets.pdf
The Forbidden VPN Secrets.pdf
Mariam Shaba20 views

MongoDB 이해하기