Skip to Content
MongoDB权威指南(第3版)
book

MongoDB权威指南(第3版)

by Shannon Bradshaw, Eoin Brazil, Kristina Chodorow
November 2021
Intermediate to advanced
410 pages
12h 1m
Chinese
Posts & Telecom Press
Content preview from MongoDB权威指南(第3版)
应用程序设计
183
最后一种方式是使用多个集合:例如,每个月的文档单独使用一个集合。每当月份变更
时,应用程序都会开始使用本月份的(空)集合,并在查询时搜索当前和以前月份的集
合。一旦集合超过特定时间,比如说
6
个月后
,可直接将其删除。这种方式几乎可以满足
任何流量,但构建应用程序时更加复杂,因为必须使用动态集合或数据库名称,并可能需
要查询多个数据库。
9.4
 数据库和集合的设计
一旦确定文档结构,就必须决定将它们放入哪些集合或数据库中。这个过程通常很简单,
但是需要记住一些指导原则。
通常来说,具有类似模式的文档应该保存在同一个集合中。
MongoDB
通常不允许合并来自
多个集合的数据,因此如果有需要一起查询或聚合的文档,则这些文档很适合放在一个大集
合中。例如,你可能有一些“形状”非常不同的文档,但是要将它们聚合,就需要让它们都
位于同一个集合中(或者如果文档位于不同的集合或数据库中,则可以使用
$merge
阶段)。
对于集合来说,需要考虑的一个大问题是锁机制(每个文档都有一个读
/
写锁)和存储
通常,如果写入工作负载很高,则可能需要考虑使用多个物理卷来减少
I/O
瓶颈
。当使用
--directoryperdb
选项时,每个数据库都可以保留在自己的目录中,这允许你将不同的数
据库挂载到不同的卷中。因此,你可能希望数据库中的所有项目都具有相近的“质量”、
相近的访问模式或相近的访问量。
假设有一个具有多个组件的应用程序:一个会创建大量低价值数据的日志组件,一个用户
集合以及几个用于保存用户生成数据的集合。用户集合具有很高的价值:用户数据的安全 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

大数据项目管理:从规划到实现

大数据项目管理:从规划到实现

Ted Malaska, Jonathan Seidman
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Spark快速大数据分析(第2版)

Spark快速大数据分析(第2版)

Jules S. Damji, Brooke Wenig, Tathagata Das, Denny Lee
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty

Publisher Resources

ISBN: 9787115576538