Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MongoDB Basic
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
yuanxin.qiu
August 28, 2013
Technology
0
93
MongoDB Basic
Rails Night 分享文件,
http://floating-brook-3473.herokuapp.com/activities/14
yuanxin.qiu
August 28, 2013
Tweet
Share
More Decks by yuanxin.qiu
See All by yuanxin.qiu
MongoDB Basic
star
0
73
Other Decks in Technology
See All in Technology
MySQLのJSON機能の活用術
ikomachi226
0
150
システムのアラート調査をサポートするAI Agentの紹介/Introduction to an AI Agent for System Alert Investigation
taddy_919
2
1.8k
茨城の思い出を振り返る ~CDKのセキュリティを添えて~ / 20260201 Mitsutoshi Matsuo
shift_evolve
PRO
1
180
セキュリティについて学ぶ会 / 2026 01 25 Takamatsu WordPress Meetup
rocketmartue
1
290
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
5
1.5k
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
3
1.3k
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.3k
toCプロダクトにおけるAI機能開発のしくじりと学び / ai-product-failures-and-learnings
rince
6
5.5k
ファインディの横断SREがTakumi byGMOと取り組む、セキュリティと開発スピードの両立
rvirus0817
1
1.1k
プロポーザルに込める段取り八分
shoheimitani
1
160
変化するコーディングエージェントとの現実的な付き合い方 〜Cursor安定択説と、ツールに依存しない「資産」〜
empitsu
4
1.3k
外部キー制約の知っておいて欲しいこと - RDBMSを正しく使うために必要なこと / FOREIGN KEY Night
soudai
PRO
12
4.6k
Featured
See All Featured
Music & Morning Musume
bryan
47
7.1k
Being A Developer After 40
akosma
91
590k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
140
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
100
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.9k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
Producing Creativity
orderedlist
PRO
348
40k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
88
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
380
Transcript
MongoDB
_id ObjectId 是 “_id”的默认类型,ObjectId使用12字节的存储空间,每个字 节两位十六进制数,是一个24位的字符串。
One to Many
Many to Many
Master to Slave 主数据库 从数据库 从数据库 备份、故障恢复、读扩展
Replica Sets server-1 server-3 server-2 副本集模式:具有Master-‐Slave模式 所有特点,但是副本集没有固定的主 服务器,当初始化的时候会通过多个
服务器投票选举出一个主服务器。 当主服务器故障时会再次通过投票 选举出新的主服务器,而原先的主服 务器恢复后则转为从服务器。 Replica Sets的在故障发生时自动切换 的机制可以及时保证写入操作.
Replica Sets 各个 Primary 与 Secondary 之 间一直保持心跳同步检测,
用于判断 Replica Sets 的状态
两种模式 hAp://database.51cto.com/art/201107/278632_1.htm
Sharding Products (Shard) Product s Product s Product s Product
s Product s Product s
Sharding l shard key l 一分片多区间 l 数据均衡器
Balancer l MMAP内存映射
Sharding Config Shard-‐1 Shard-‐2 Mongos . . .
Sharding 要构建一个MongoDB Sharding Cluster,需要三种角色: 1、Sharding Server mongod实例,用于存储实际的数据块
2、Config Server mongod实例,存储了整个Cluster Metadata,其中包括chunk信息,确保元数 据完整性 3、Route Server mongos实例,前端路由,客户端由此接入,且让整个集群看上去像单一进程数据 库,多个mongos可实现负载平衡,提高客户端的接入性能
分片机制
分片机制 l MongoDB 的分片是指定一个分片 key 来进行,数据按范围分成不同 的 chunk,每个 chunk 的大小有限制
l 有多个分片节点保存这些chunk,每个节点保存一部分的 chunk l 当一个chunk超过其限制的最大体积时,会分裂成两个小的chunk l 当chunk在分片节点中分布不均衡时,会引发 chunk 迁移操作
Replica Sets + Sharding
备份与恢复 l mongodump –d db_name -‐o backup l mongorestore
–d db_name –drop backup/db_name fsync 锁来保证数据同步