Get / create a 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 passed to the creat
(
self,
database: Database[_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[ClientSession] = None,
**kwargs: Any,
)
| 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 | |
| 194 | .. versionchanged:: 4.0 |
| 195 | Removed the reindex, map_reduce, inline_map_reduce, |
| 196 | parallel_scan, initialize_unordered_bulk_op, |
nothing calls this directly
no test coverage detected