MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _connect

Method _connect

test/asynchronous/__init__.py:174–195  ·  view source on GitHub ↗
(self, host, port, **kwargs)

Source from the content-addressed store, hash-verified

172 return self._hello
173
174 async def _connect(self, host, port, **kwargs):
175 kwargs.update(self.default_client_options)
176 client: AsyncMongoClient = pymongo.AsyncMongoClient(
177 host, port, serverSelectionTimeoutMS=5000, **kwargs
178 )
179 try:
180 try:
181 await client.admin.command("ping") # Can we connect?
182 except pymongo.errors.OperationFailure as exc:
183 # SERVER-32063
184 self.connection_attempts.append(
185 f"connected client {client!r}, but legacy hello failed: {exc}"
186 )
187 else:
188 self.connection_attempts.append(f"successfully connected client {client!r}")
189 # If connected, then return client with default timeout
190 return pymongo.AsyncMongoClient(host, port, **kwargs)
191 except pymongo.errors.ConnectionFailure as exc:
192 self.connection_attempts.append(f"failed to connect client {client!r}: {exc}")
193 return None
194 finally:
195 await client.close()
196
197 async def _init_client(self):
198 self.mongoses = []

Callers 1

_init_clientMethod · 0.95

Calls 4

closeMethod · 0.95
AsyncMongoClientMethod · 0.80
updateMethod · 0.45
commandMethod · 0.45

Tested by

no test coverage detected