本文介绍了pymongo复制辅助readreference不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有MongoDB 2.6和2副本集,并且我们使用pymongo
驱动程序并将Mongo复制集与以下URL连接起来
we have MongoDB 2.6 and 2 Replica Set, and we use pymongo
driver and connect Mongo Replicat Set with the following url
mongodb://admin:[email protected]:10011:127.0.0.1:10012,127.0.0.1:10013/db?replicaSet=replica
使用python代码
from pymongo import MongoClient
url = 'mongodb://admin:[email protected]:10011:127.0.0.1:10012,127.0.0.1:10013/db?replicaSet=replica'
db = 'db'
db = MongoClient(
url,
readPreference='secondary',
secondary_acceptable_latency_ms=1000,
)[db]
db.test.find_one()
# more read operations
但是事实证明,该连接没有从辅助副本集读取任何内容,在这两个辅助副本集的mongo日志中找不到连接日志
but it turns out that the connection didn't read anything from secondary replicat set, no connection log could be found in mongo log on these 2 secondary replica set
推荐答案
尝试配置 ReplicaSetConnection .例如:
Try to configure a ReplicaSetConnection instead. For instance:
>>> db = ReplicaSetConnection("morton.local:27017", replicaSet='foo').test
>>> from pymongo import ReadPreference
>>> db.read_preference = ReadPreference.SECONDARY
这篇关于pymongo复制辅助readreference不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!