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版)
28
3
如果仔细研究这些示例,你可能会注意到,除了简单的插入之外,这两个对
insertMany
用的输出提示还有其他操作可能支持批量写入。虽然
insertMany
不支持插入以外的操作,
MongoDB
确实有一个批量写入
API
允许在单个调用中批量处理多个不同类型的操作
这部分内容超出了本章的范围,如果你感兴趣,可以在
MongoDB
的相关文档中查阅关于
批量写入
API
的内容。
3.1.2
 插入校验
MongoDB
会对要插入的数据进行最基本的检查:检查文档的基本结构,如果不存在
"_id"
字段,则自动添加一个。其中一项最基本的结构检查就是文档大小:所有文档都必须小于
16MB
。这是一个人为设定的限制
(将来可能会提高),主要是为了防止不良的模式设计并
确保性能上的一致。要查看
doc
文档的二进制
JSON
BSON
)大小
(以字节为单位),可
以在
shell
中执行
Object.bsonsize(doc)
为了让你对
16MB
的数据量有个概念,以《战争与和平》为例,整部著作也只有
3.14MB
由于仅做最基本的检查,这意味着可以很容易地插入无效数据(如果你尝试这么做的话)。
因此,应该只允许受信任的源(比如应用程序服务器)连接到数据库。所有主流语言的
MongoDB
驱动程序以及大部分其他语言的驱动程序
,在向数据库发送任何内容之前,都会
进行各种无效数据的校验(比如文档过大、包含非
UTF-8
字符串,或使用无法识别的类型)
3.1.3
 插入
MongoDB 3.0
之前,
insert
是在
MongoDB
中插入文档的主要方法。在 ...
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