You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to connect to a replica set MongoDB instance over an SSH tunnel you
98
+
If you try to connect to a MongoDB replica set over an SSH tunnel, you
90
99
will receive the following error:
91
100
92
101
.. code-block:: python
93
102
94
-
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 1560, in count
95
-
return self._count(cmd, collation, session)
96
-
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 1504, in _count
97
-
with self._socket_for_reads() as (connection, slave_ok):
98
-
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
99
-
return self.gen.next()
100
-
File "/Library/Python/2.7/site-packages/pymongo/mongo_client.py", line 982, in _socket_for_reads
101
-
server = topology.select_server(read_preference)
102
-
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 224, in select_server
103
-
address))
104
-
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 183, in select_servers
105
-
selector, server_timeout, address)
106
-
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
107
-
self._error_message(selector))
108
-
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: timed out
109
-
110
-
This is due to the fact that PyMongo discovers replica set members using the response from the isMaster command which
111
-
then contains the address and ports of the other members. However, these addresses and ports will not be accessible through the SSH tunnel. Thus, this behavior is unsupported.
112
-
You can, however, connect directly to a single MongoDB node using the directConnection=True option with SSH tunneling.
103
+
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 1560, in count
104
+
return self._count(cmd, collation, session)
105
+
File "/Library/Python/2.7/site-packages/pymongo/collection.py", line 1504, in _count
106
+
with self._socket_for_reads() as (connection, slave_ok):
107
+
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
108
+
return self.gen.next()
109
+
File "/Library/Python/2.7/site-packages/pymongo/mongo_client.py", line 982, in _socket_for_reads
110
+
server = topology.select_server(read_preference)
111
+
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 224, in select_server
112
+
address))
113
+
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 183, in select_servers
114
+
selector, server_timeout, address)
115
+
File "/Library/Python/2.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop
116
+
self._error_message(selector))
117
+
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: timed out
118
+
119
+
This occurs because {+driver-short+} discovers replica set members by using the response
120
+
from the ``isMaster`` command, which contains the addresses and ports of the other
121
+
replica set members. However, you can't access these addresses and ports through the SSH
122
+
tunnel.
123
+
124
+
Instead, you can connect directly to a single MongoDB node by using the
125
+
``directConnection=True`` option with SSH tunneling.
0 commit comments