OPTIONS
翻译或纠错本页面

复制集主节点

在复制集中,主节点是唯一能够接收写请求的节点。MongoDB在 主节点 上进行写操作,并会将这些操作记录到主节点的 oplog 中。 从节点 会将oplog复制到其本机并将这些操作应用到其自己的数据集上。

在拥有下述三个成员的复制集中,主节点将接收所有的写请求,而从节点会将oplog复制到本机并在其自己的数据集上应用这些操作。

Diagram of default routing of reads and writes to the primary.

Diagram of default routing of reads and writes to the primary.

复制集中任何成员都可以接收读请求。但是默认情况下,应用程序会直接连接到在主节点上进行读操作。阅读 复制集读选项 可以获得更多关于更改默认读请求目标的信息。

复制集最多只能拥有一个主节点。一旦当前的主节点不可用了,复制集就会选举出新的主节点。参见 复制集选举 获得更多信息。

在拥有下述三个成员的复制集中,一旦当前主节点不可用了,就会触发选举机制,并将在剩下的从节点中选举出一个新的主节点。

Diagram of an election of a new primary. In a three member replica set with two secondaries, the primary becomes unreachable. The loss of a primary triggers an election where one of the secondaries becomes the new primary

Diagram of an election of a new primary. In a three member replica set with two secondaries, the primary becomes unreachable. The loss of a primary triggers an election where one of the secondaries becomes the new primary

ON THIS PAGE