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

Method __init__

gridfs/asynchronous/grid_file.py:73–112  ·  view source on GitHub ↗

Create a new instance of :class:`GridFS`. Raises :class:`TypeError` if `database` is not an instance of :class:`~pymongo.database.Database`. :param database: database to use :param collection: root collection to use .. versionchanged:: 4.0 Remove

(self, database: AsyncDatabase[Any], collection: str = "fs")

Source from the content-addressed store, hash-verified

71 """An instance of GridFS on top of a single Database."""
72
73 def __init__(self, database: AsyncDatabase[Any], collection: str = "fs"):
74 """Create a new instance of :class:`GridFS`.
75
76 Raises :class:`TypeError` if `database` is not an instance of
77 :class:`~pymongo.database.Database`.
78
79 :param database: database to use
80 :param collection: root collection to use
81
82 .. versionchanged:: 4.0
83 Removed the `disable_md5` parameter. See
84 :ref:`removed-gridfs-checksum` for details.
85
86 .. versionchanged:: 3.11
87 Running a GridFS operation in a transaction now always raises an
88 error. GridFS does not support multi-document transactions.
89
90 .. versionchanged:: 3.7
91 Added the `disable_md5` parameter.
92
93 .. versionchanged:: 3.1
94 Indexes are only ensured on the first write to the DB.
95
96 .. versionchanged:: 3.0
97 `database` must use an acknowledged
98 :attr:`~pymongo.database.Database.write_concern`
99
100 .. seealso:: The MongoDB documentation on `gridfs <https://dochub.mongodb.org/core/gridfs>`_.
101 """
102 if not isinstance(database, AsyncDatabase):
103 raise TypeError(f"database must be an instance of Database, not {type(database)}")
104
105 database = _clear_entity_type_registry(database)
106
107 if not database.write_concern.acknowledged:
108 raise ConfigurationError("database must use acknowledged write_concern")
109
110 self._collection = database[collection]
111 self._files = self._collection.files
112 self._chunks = self._collection.chunks
113
114 def new_file(self, **kwargs: Any) -> AsyncGridIn:
115 """Create a new file in GridFS.

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 2

ConfigurationErrorClass · 0.90

Tested by

no test coverage detected