mongodb - 写入 mongo 数据库副本集 : take care of primary when writing?

标签 mongodb

我的 mongo 数据库有一个主节点和两个辅助节点。

写入时需要注意哪个节点是主节点吗? 或者 mongo db 是否自动将写操作从辅助节点重定向到主节点?

这里讨论了类似的问题,但我的问题没有得到明确的回答: In a primary-secondary Mongo db set if you accidentally write to a secondary would it reflect in primary it gets routed to primary

最佳答案

这实际上是关于如何配置副本集的连接字符串以及驱动程序如何正确“发现”成员。

为了具体说明有关所引用问题的陈述,不可能写入辅助数据库,因为写入只能写入集合中的主要数据库。如果主节点发生故障,则需要选举主节点。在选举期间,写入操作将失败,因为当前没有主节点为其提供服务。

至于驱动程序“如何”确定哪个是当前“主要”的具体机制,meta spec for driver implementations中有更多详细信息。 .

但一般情况是,只要您指定“足够”的可能主机来联系副本集(并且所有这些主机对于三个节点来说都是一个很好的情况),那么驱动程序就能够“检查”成员并确定哪个是“主要”并且可以写入。

因此,“故障转移”是副本集配置的一部分,“检测”是由驱动程序完成的,驱动程序可以与“至少一个节点”对话并要求返回哪个节点是当前的主节点,以便可以用于将来的写入操作。

关于mongodb - 写入 mongo 数据库副本集 : take care of primary when writing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26091481/

相关文章:

mongodb - 设置任何需要 50ms 或更长时间的进程都会记录在 mongod.conf 中

node.js - JsonWebToken错误: jwt must be a string

mongodb - ElasticSearch自动完成返回0次

python - 模块未找到错误: No module named 'pymongo' with Docker and Airflow

mongodb - 如何在 Mongodb 中获取条件字段

java - 使用java中的运算符将字符串解析为mongodb查询文档

Mongodb atlas搜索: how to make use of multiple analyzers for the same query string,以便至少返回一些结果

javascript - Heroku 部署错误 : Cannot get Node App running after Deploy : Cannot find module '/app/web.js'

mongodb - 无法下载mongovue

python - Mongoengine + Django : strange errors with fields during rendering