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

Class Collection

pymongo/synchronous/collection.py:136–3691  ·  view source on GitHub ↗

A Mongo collection.

Source from the content-addressed store, hash-verified

134
135
136class Collection(common.BaseObject, Generic[_DocumentType]):
137 """A Mongo collection."""
138
139 def __init__(
140 self,
141 database: Database[_DocumentType],
142 name: str,
143 create: Optional[bool] = False,
144 codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None,
145 read_preference: Optional[_ServerMode] = None,
146 write_concern: Optional[WriteConcern] = None,
147 read_concern: Optional[ReadConcern] = None,
148 session: Optional[ClientSession] = None,
149 **kwargs: Any,
150 ) -> None:
151 """Get / create a Mongo collection.
152
153 Raises :class:`TypeError` if `name` is not an instance of
154 :class:`str`. Raises :class:`~pymongo.errors.InvalidName` if `name` is
155 not a valid collection name. Any additional keyword arguments will be used
156 as options passed to the create command. See
157 :meth:`~pymongo.database.Database.create_collection` for valid
158 options.
159
160 If `create` is ``True``, `collation` is specified, or any additional
161 keyword arguments are present, a ``create`` command will be
162 sent, using ``session`` if specified. Otherwise, a ``create`` command
163 will not be sent and the collection will be created implicitly on first
164 use. The optional ``session`` argument is *only* used for the ``create``
165 command, it is not associated with the collection afterward.
166
167 :param database: the database to get a collection from
168 :param name: the name of the collection to get
169 :param create: If ``True``, force collection
170 creation even without options being set.
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: A
186 :class:`~pymongo.client_session.ClientSession` that is used with
187 the create collection command.
188 :param kwargs: Additional keyword arguments will
189 be passed as options for the create collection command.
190
191 .. versionchanged:: 4.2
192 Added the ``clusteredIndex`` and ``encryptedFields`` parameters.
193

Callers 11

test_generic_argumentsFunction · 0.90
test_get_collMethod · 0.90
test_equalityMethod · 0.90
test_boolMethod · 0.90
__getitem__Method · 0.90
get_collectionMethod · 0.90
create_collectionMethod · 0.90
__getitem__Method · 0.85
with_optionsMethod · 0.85

Calls

no outgoing calls

Tested by 5

test_generic_argumentsFunction · 0.72
test_get_collMethod · 0.72
test_equalityMethod · 0.72
test_boolMethod · 0.72