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

Method __getattr__

pymongo/synchronous/database.py:229–241  ·  view source on GitHub ↗

Get a collection of this database by name. Raises InvalidName if an invalid collection name is used. :param name: the name of the collection to get

(self, name: str)

Source from the content-addressed store, hash-verified

227 return f"{type(self).__name__}({self._client!r}, {self._name!r})"
228
229 def __getattr__(self, name: str) -> Collection[_DocumentType]:
230 """Get a collection of this database by name.
231
232 Raises InvalidName if an invalid collection name is used.
233
234 :param name: the name of the collection to get
235 """
236 if name.startswith("_"):
237 raise AttributeError(
238 f"{type(self).__name__} has no attribute {name!r}. To access the {name}"
239 f" collection, use database[{name!r}]."
240 )
241 return self.__getitem__(name)
242
243 def __getitem__(self, name: str) -> Collection[_DocumentType]:
244 """Get a collection of this database by name.

Callers

nothing calls this directly

Calls 1

__getitem__Method · 0.95

Tested by

no test coverage detected