Closed Ideonics-in closed 5 years ago
By default, mongo-connector uses the readPreference of primary. In this mode the client will fail if it cannot read from the primary of the replica set. To configure mongo-connector to read from a secondary you can use a readPreference of primaryPreferred
, secondary
, or secondaryPreferred
.
To set this option, pass the MongoDB address in the MongoDB connection string format. For example, mongo-connector -m 'mongodb://localhost:27017/?readPreference=secondary' ...
Dear Shane, Thanks for the suggestion . We tried it out and the result remains same. Have attached the screenshot below Please have a look regards,
Are you connecting through a mongos? If so, https://github.com/mongodb-labs/mongo-connector/pull/665 should fix this problem.
Otherwise, if you're connecting to a replica set, I can't reproduce your problem. Mongo-connector 2.4.1 and 2.5.0 correctly pass the readPreference
when connecting to a replica set as far as I can tell. Can you start the connector with verbose output (-v
) and post the log file (be sure to remove sensitive information)? What versions of PyMongo and mongo-connector are you using?
I have the same issue, tried from both servers, the master and replica:
mongo-connector -v -m 'mongodb://localhost:27017/?readPreference=secondary' -t elasticsearch.mydomain.com:9200 -d elastic2_doc_manager
with and without readPreference, result is same error about "Primary". It still looks for primary I guess ignoring the setting? Any ideas guys, did someone solved it? Thanks!
Hi, did anyone solve this? I cannot access any of my collections on the Atlas website either (in the cluster I'm trying to connect to, that is).
I tried replicating the issue, and it looks to me like the mongo-connector is honoring the 'readPreference=secondary' setting:
draft $ python -m venv env
draft $ env/bin/python -m pip install mongo-connector
Collecting mongo-connector
Downloading https://files.pythonhosted.org/packages/97/6b/839c15a24959a54e15302a07fda2bed8513b79674ff085b6c9028b90b8bf/mongo_connector-3.1.1-py2.py3-none-any.whl (60kB)
100% |████████████████████████████████| 61kB 118kB/s
Collecting importlib-resources (from mongo-connector)
Using cached https://files.pythonhosted.org/packages/2f/f7/b4aa02cdd3ee7ebba375969d77c00826aa15c5db84247d23c89522dccbfa/importlib_resources-1.0.2-py2.py3-none-any.whl
Collecting importlib-metadata>=0.6 (from mongo-connector)
Using cached https://files.pythonhosted.org/packages/c4/e4/b5dbc3364c296e0510e739c4e09daba535e9676ffde6c1312c2210c76bf0/importlib_metadata-0.8-py2.py3-none-any.whl
Collecting pymongo>=2.9 (from mongo-connector)
Using cached https://files.pythonhosted.org/packages/d7/ac/d2e324c1f9bcf653fa106785371a16b4709506a35b04948655de8b961a85/pymongo-3.7.2-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting autocommand (from mongo-connector)
Using cached https://files.pythonhosted.org/packages/61/55/9fb7c5a63fe0a797054034ce9aeacded2ca078690c63413ebfa06c47ee56/autocommand-2.2.1-py3-none-any.whl
Collecting zipp>=0.3.2 (from importlib-metadata>=0.6->mongo-connector)
Using cached https://files.pythonhosted.org/packages/00/42/10a1f8d29eaf9c7f2b555a5d1d602b9261f2a0cbec08f8f23d9056f5915d/zipp-0.3.3-py2.py3-none-any.whl
Installing collected packages: importlib-resources, zipp, importlib-metadata, pymongo, autocommand, mongo-connector
Successfully installed autocommand-2.2.1 importlib-metadata-0.8 importlib-resources-1.0.2 mongo-connector-3.1.1 pymongo-3.7.2 zipp-0.3.3
You are using pip version 18.1, however version 19.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
draft $ env/bin/mongo-connector -v -m mongodb://localhost/?readPreference=secondary -t localhost -d mongo_doc_manager
Logging to /Users/jaraco/draft/mongo-connector.log.
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/mongo_connector/util.py", line 107, in wrapped
func(*args, **kwargs)
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/mongo_connector/connector.py", line 399, in run
**self.kwargs
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/mongo_connector/oplog_manager.py", line 142, in __init__
if not self.oplog.find_one():
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/pymongo/collection.py", line 1262, in find_one
for result in cursor.limit(-1):
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/pymongo/cursor.py", line 1189, in next
if len(self.__data) or self._refresh():
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/pymongo/cursor.py", line 1104, in _refresh
self.__send_message(q)
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/pymongo/cursor.py", line 931, in __send_message
operation, exhaust=self.__exhaust, address=self.__address)
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1129, in _send_message_with_response
server = topology.select_server(operation.read_preference)
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/pymongo/topology.py", line 224, in select_server
address))
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/pymongo/topology.py", line 183, in select_servers
selector, server_timeout, address)
File "/Users/jaraco/draft/env/lib/python3.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: No replica set members match selector "Secondary(tag_sets=None, max_staleness=-1)"
I got that error because I specified a standalone mongod and not a replica set, so there was no secondary. Nevertheless, you can see from the error that it is indeed attempting to resolve a secondary from a replica set, as indicated.
If you're having issues with mongo connector being unable to connect to a secondary, first try connecting to the secondary using just pymongo.
If you're still having issues, please provide more information as directed.
Can you start the connector with verbose output (
-v
) and post the log file (be sure to remove sensitive information)? What versions of PyMongo and mongo-connector are you using?
Hi, We are using mongo-connector for the first time. Our topology is as shown in the attached file. Mongodb Replication Topology.pdf
We are trying to use mongo-connector, to replicate from secondary member to local systems. However, we get the following error,
No replica set members match selector "Primary()"
Any suggestions would be greatly appreciated
Thanks in advance