MongoDB 副本集 - 具有 readPreference 的 copyDatabase?
MongoDB replica set - copyDatabase with readPreference?
根据 Connection String URI Syntax 上关于副本集的文档,我们有:
The following connects to a replica set with three members and distributes reads to the secondaries:
mongodb://example1.com,example2.com/?replicaSet=test&readPreference=secondary
这正是我需要做的,但是我正在尝试为 copyDatabase
命令确定要使用的正确语法(如果甚至支持 readPreference
)。它的主机 URI 语法如下所示:
test/example1.com,example2.com
...例如...
db.copyDatabase('myDb', 'myDb', 'test/example1.com,example2.com')
我可以在最后加上 ?readPreference=secondary
并让它按预期工作吗?我没有方便的方法在我的环境中自己测试这个,或者我会。希望这里的人可能知道他们的头脑。
阅读偏好是一个client/driver-side概念。服务器不知道请求的读取首选项,因此您无法在服务器端验证读取首选项。您可以验证某些查询是否通过 mongostat
发送到辅助服务器,或者您可以在每个数据库服务器上使用 db.serverStatus().opcounters
比较 'query' 计数预查询和 post-查询.对于数据库服务器状态的完整列表,请使用 db.serverStatus()
根据 Connection String URI Syntax 上关于副本集的文档,我们有:
The following connects to a replica set with three members and distributes reads to the secondaries:
mongodb://example1.com,example2.com/?replicaSet=test&readPreference=secondary
这正是我需要做的,但是我正在尝试为 copyDatabase
命令确定要使用的正确语法(如果甚至支持 readPreference
)。它的主机 URI 语法如下所示:
test/example1.com,example2.com
...例如...
db.copyDatabase('myDb', 'myDb', 'test/example1.com,example2.com')
我可以在最后加上 ?readPreference=secondary
并让它按预期工作吗?我没有方便的方法在我的环境中自己测试这个,或者我会。希望这里的人可能知道他们的头脑。
阅读偏好是一个client/driver-side概念。服务器不知道请求的读取首选项,因此您无法在服务器端验证读取首选项。您可以验证某些查询是否通过 mongostat
发送到辅助服务器,或者您可以在每个数据库服务器上使用 db.serverStatus().opcounters
比较 'query' 计数预查询和 post-查询.对于数据库服务器状态的完整列表,请使用 db.serverStatus()