我想用 MongoDB 扩展读取。为此,我可以设置主从复制或副本集,但如果我像这样创建与 Mongo 的连接:
from pymongo import ReplicaSetConnection, ReadPreference
from pymongo.errors import ConnectionFailure
try:
connection = ReplicaSetConnection("somehost:10000", replicaSet='myapp_repl',
read_preference=ReadPreference.SECONDARY)
except ConnectionFailure ...
或者:
from pymongo.master_slave_connection import MasterSlaveConnection
from pymongo.errors import ConnectionFailure
try:
master = Connection(host="somehost", port=10000)
slave1 = Connection(host="somehost", port=10001)
slave2 = Connection(host="somehost", port=10002)
connection = MasterSlaveConnection(master, slaves=[slave1, slave2])
except ConnectionFailure ...
pymongo驱动程序将在副本集辅助服务器/从服务器之间分发查询。在这种情况下,primary/master 不会处理查询,所以如果我有 2 个节点,我不会增强读取能力,因为只有 1 个节点会处理查询。如何让主从(主要和次要)处理查询?