client = MongoClient(<<MONGODB URL>>)
db=client.admin
serverStatusResult=db.command("serverStatus")
mongodb://USERNAME:PASS...@CLUSTERNAME-shard-00-00-huhjd.mongodb.net:27017,CLUSTERNAME-shard-00-01-huhjd.mongodb.net:27017,CLUSTERNAME-shard-00-02-huhjd.mongodb.net:27017/DATABASE?ssl=true&replicaSet=CLUSTERNAME-shard-0&authSource=admin
mongodb://USERNAME:PASS...@CLUSTERNAME-shard-00-00-huhjd.mongodb.net:27017,CLUSTERNAME-shard-00-01-huhjd.mongodb.net:27017,CLUSTERNAME>-shard-00-02-huhjd.mongodb.net:27017/admin?ssl=true&replicaSet=CLUSTERNAME0-shard-0&authSource=admin"
/Users/Charles/anaconda/envs/py36/lib/python3.6/site-packages/pymongo/database.py in command(self, command, value, check, allowable_errors, read_preference, codec_options, **kwargs)
489 """
490 client = self.__client
--> 491 with client._socket_for_reads(read_preference) as (sock_info, slave_ok):
492 return self._command(sock_info, command, slave_ok, value,
493 check, allowable_errors, read_preference,
/Users/anaconda/envs/py36/lib/python3.6/contextlib.py in __enter__(self)
80 def __enter__(self):
81 try:
---> 82 return next(self.gen)
83 except StopIteration:
84 raise RuntimeError("generator didn't yield") from None
/Users/Charles/anaconda/envs/py36/lib/python3.6/site-packages/pymongo/mongo_client.py in _socket_for_reads(self, read_preference)
857 topology = self._get_topology()
858 single = topology.description.topology_type == TOPOLOGY_TYPE.Single
--> 859 with self._get_socket(read_preference) as sock_info:
860 slave_ok = (single and not sock_info.is_mongos) or (
861 preference != ReadPreference.PRIMARY)
/Users/anaconda/envs/py36/lib/python3.6/contextlib.py in __enter__(self)
80 def __enter__(self):
81 try:
---> 82 return next(self.gen)
83 except StopIteration:
84 raise RuntimeError("generator didn't yield") from None
/Users/charles/anaconda/envs/py36/lib/python3.6/site-packages/pymongo/mongo_client.py in _get_socket(self, selector)
821 @contextlib.contextmanager
822 def _get_socket(self, selector):
--> 823 server = self._get_topology().select_server(selector)
824 try:
825 with server.get_socket(self.__all_credentials) as sock_info:
/Users/charles/anaconda/envs/py36/lib/python3.6/site-packages/pymongo/topology.py in select_server(self, selector, server_selection_timeout, address)
212 return random.choice(self.select_servers(selector,
213 server_selection_timeout,
--> 214 address))
215
216 def select_server_by_address(self, address,
/Users/charles/anaconda/envs/py36/lib/python3.6/site-packages/pymongo/topology.py in select_servers(self, selector, server_selection_timeout, address)
187 if server_timeout == 0 or now > end_time:
188 raise ServerSelectionTimeoutError(
--> 189 self._error_message(selector))
190
191 self._ensure_opened()
ServerSelectionTimeoutError: connection closed
I posted this on stack exchange as well but I figure I might as well post it here as well. Maybe you can help?
I've been trying to follow this tutorial which walks you through the steps of setting up a cluster and connecting to it from python and I am having some problems.
This is the code I am trying to run:client = MongoClient(<<MONGODB URL>>)
db=client.admin
serverStatusResult=db.command("serverStatus")My URI connection string is here (I've replaced everything in caps):
One issue I am sure is I have everything but the DATABASE field. I haven't created it yet so what, if anything am I supposed to put there? After reading the URI documentation I discovered that's optional so I've tried removing everything after the backslash of the last shard. That didn't work. I've also tried using the URI string below listed on the MongoDB Drivers Page and that didn't work: