Create a new :class:`~pymongo.collection.Collection` in this database. Normally collection creation is automatic. This method should only be used to specify options on creation. :class:`~pymongo.errors.CollectionInvalid` will be raised if the collection alrea
(
self,
name: str,
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,
check_exists: Optional[bool] = True,
**kwargs: Any,
)
| 478 | |
| 479 | @_csot.apply |
| 480 | def create_collection( |
| 481 | self, |
| 482 | name: str, |
| 483 | codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, |
| 484 | read_preference: Optional[_ServerMode] = None, |
| 485 | write_concern: Optional[WriteConcern] = None, |
| 486 | read_concern: Optional[ReadConcern] = None, |
| 487 | session: Optional[ClientSession] = None, |
| 488 | check_exists: Optional[bool] = True, |
| 489 | **kwargs: Any, |
| 490 | ) -> Collection[_DocumentType]: |
| 491 | """Create a new :class:`~pymongo.collection.Collection` in this |
| 492 | database. |
| 493 | |
| 494 | Normally collection creation is automatic. This method should |
| 495 | only be used to specify options on |
| 496 | creation. :class:`~pymongo.errors.CollectionInvalid` will be |
| 497 | raised if the collection already exists. |
| 498 | |
| 499 | :param name: the name of the collection to create |
| 500 | :param codec_options: An instance of |
| 501 | :class:`~bson.codec_options.CodecOptions`. If ``None`` (the |
| 502 | default) the :attr:`codec_options` of this :class:`Database` is |
| 503 | used. |
| 504 | :param read_preference: The read preference to use. If |
| 505 | ``None`` (the default) the :attr:`read_preference` of this |
| 506 | :class:`Database` is used. |
| 507 | :param write_concern: An instance of |
| 508 | :class:`~pymongo.write_concern.WriteConcern`. If ``None`` (the |
| 509 | default) the :attr:`write_concern` of this :class:`Database` is |
| 510 | used. |
| 511 | :param read_concern: An instance of |
| 512 | :class:`~pymongo.read_concern.ReadConcern`. If ``None`` (the |
| 513 | default) the :attr:`read_concern` of this :class:`Database` is |
| 514 | used. |
| 515 | :param collation: An instance of |
| 516 | :class:`~pymongo.collation.Collation`. |
| 517 | :param session: a |
| 518 | :class:`~pymongo.client_session.ClientSession`. |
| 519 | :param check_exists: if True (the default), send a listCollections command to |
| 520 | check if the collection already exists before creation. |
| 521 | :param kwargs: additional keyword arguments will |
| 522 | be passed as options for the `create collection command`_ |
| 523 | |
| 524 | All optional `create collection command`_ parameters should be passed |
| 525 | as keyword arguments to this method. Valid options include, but are not |
| 526 | limited to: |
| 527 | |
| 528 | - ``size`` (int): desired initial size for the collection (in |
| 529 | bytes). For capped collections this size is the max |
| 530 | size of the collection. |
| 531 | - ``capped`` (bool): if True, this is a capped collection |
| 532 | - ``max`` (int): maximum number of objects if capped (optional) |
| 533 | - ``timeseries`` (dict): a document specifying configuration options for |
| 534 | timeseries collections |
| 535 | - ``expireAfterSeconds`` (int): the number of seconds after which a |
| 536 | document in a timeseries collection expires |
| 537 | - ``validator`` (dict): a document specifying validation rules or expressions |