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

Method __init__

pymongo/asynchronous/collection.py:140–266  ·  view source on GitHub ↗

Get / create an asynchronous Mongo collection. Raises :class:`TypeError` if `name` is not an instance of :class:`str`. Raises :class:`~pymongo.errors.InvalidName` if `name` is not a valid collection name. Any additional keyword arguments will be used as options passe

(
        self,
        database: AsyncDatabase[_DocumentType],
        name: str,
        create: Optional[bool] = False,
        codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
        read_preference: Optional[_ServerMode] = None,
        write_concern: Optional[WriteConcern] = None,
        read_concern: Optional[ReadConcern] = None,
        session: Optional[AsyncClientSession] = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

138 """An asynchronous Mongo collection."""
139
140 def __init__(
141 self,
142 database: AsyncDatabase[_DocumentType],
143 name: str,
144 create: Optional[bool] = False,
145 codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
146 read_preference: Optional[_ServerMode] = None,
147 write_concern: Optional[WriteConcern] = None,
148 read_concern: Optional[ReadConcern] = None,
149 session: Optional[AsyncClientSession] = None,
150 **kwargs: Any,
151 ) -> None:
152 """Get / create an asynchronous Mongo collection.
153
154 Raises :class:`TypeError` if `name` is not an instance of
155 :class:`str`. Raises :class:`~pymongo.errors.InvalidName` if `name` is
156 not a valid collection name. Any additional keyword arguments will be used
157 as options passed to the create command. See
158 :meth:`~pymongo.asynchronous.database.AsyncDatabase.create_collection` for valid
159 options.
160
161 If `create` is ``True``, `collation` is specified, or any additional
162 keyword arguments are present, a ``create`` command will be
163 sent, using ``session`` if specified. Otherwise, a ``create`` command
164 will not be sent and the collection will be created implicitly on first
165 use. The optional ``session`` argument is *only* used for the ``create``
166 command, it is not associated with the collection afterward.
167
168 :param database: the database to get a collection from
169 :param name: the name of the collection to get
170 :param create: **Not supported by AsyncCollection**.
171 :param codec_options: An instance of
172 :class:`~bson.codec_options.CodecOptions`. If ``None`` (the
173 default) database.codec_options is used.
174 :param read_preference: The read preference to use. If
175 ``None`` (the default) database.read_preference is used.
176 :param write_concern: An instance of
177 :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the
178 default) database.write_concern is used.
179 :param read_concern: An instance of
180 :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the
181 default) database.read_concern is used.
182 :param collation: An instance of
183 :class:`~pymongo.collation.Collation`. If a collation is provided,
184 it will be passed to the create collection command.
185 :param session: **Not supported by AsyncCollection**.
186 :param kwargs: **Not supported by AsyncCollection**.
187
188 .. versionchanged:: 4.2
189 Added the ``clusteredIndex`` and ``encryptedFields`` parameters.
190
191 .. versionchanged:: 4.0
192 Removed the reindex, map_reduce, inline_map_reduce,
193 parallel_scan, initialize_unordered_bulk_op,
194 initialize_ordered_bulk_op, group, count, insert, save,
195 update, remove, find_and_modify, and ensure_index methods. See the
196 :ref:`pymongo4-migration-guide`.
197

Callers

nothing calls this directly

Calls 3

_createMethod · 0.95
InvalidNameClass · 0.90
_replaceMethod · 0.80

Tested by

no test coverage detected