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版)
18
2
在这
4
字节中也隐含了每个文档的创建时间。大多数驱动程序提供了从
ObjectId
中提
取此信息的方法。
由于
ObjectId
使用的是当前时间,因此很多人会担心需要对服务器进行时钟同步。尽管
出于其他原因进行时钟同步是一个好主意(参见
24.5.1
节)
,但在这里实际的时间戳对
ObjectId
并不重要,只要它总是不停增加就可以了(每秒
1
)。
ObjectId
中接下来的
5
字节是一个随机值。最后
3
字节是一个计数器,以一个随机数作为
起始值,用来避免在不同机器上生成相互冲突的
ObjectId
因此,前
9
字节保证了
ObjectId
1
秒内跨机器和进程的唯一性。最后
3
字节只是一个
递增计数器,负责确保单个进程中
1
秒内的唯一性
。这允许在
1
秒内为
每个进程
生成多达
256
3
16 777 216
)个唯一的
ObjectId
2.
自动生成
_id
如前所述,如果插入文档时不存在
"_id"
键,则会自动创建一个并添加到插入的文档中。
这个工作可以由
MongoDB
的服务器端处理,但通常由客户端的驱动程序来完成。
2.7
 使用
MongoDB shell
本节介绍如何将
shell
作为命令行工具包的一部分来使用,如何对其进行自定义,以及
shell
的一些高级功能。
尽管在上面的例子中只是连接到了一个本地的
mongod
实例
,但实际上可以将
shell
连接到
机器可以访问的任何
MongoDB
实例
。要想连接到其他机器或端口上的
mongod
,需要在启
shell
时指定主机名、端口和数据库:
$ mongo some-host:30000/myDB ...
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