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

Method create_collection

pymongo/synchronous/database.py:480–637  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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

Callers 15

test_list_collectionsMethod · 0.95
setUpMethod · 0.45
test_check_existsMethod · 0.45
setUpClusterMethod · 0.45
create_with_schemaFunction · 0.45
setUpMethod · 0.45

Calls 7

_get_encrypted_fieldsMethod · 0.95
_createMethod · 0.95
CollectionInvalidClass · 0.90
CollectionClass · 0.90
getMethod · 0.45
_tmp_sessionMethod · 0.45

Tested by 15

test_list_collectionsMethod · 0.76
setUpMethod · 0.36
test_check_existsMethod · 0.36
setUpClusterMethod · 0.36
create_with_schemaFunction · 0.36
setUpMethod · 0.36