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

Method __init__

gridfs/synchronous/grid_file.py:462–523  ·  view source on GitHub ↗

Create a new instance of :class:`GridFSBucket`. Raises :exc:`TypeError` if `database` is not an instance of :class:`~pymongo.database.Database`. Raises :exc:`~pymongo.errors.ConfigurationError` if `write_concern` is not acknowledged. :param database: databa

(
        self,
        db: Database[Any],
        bucket_name: str = "fs",
        chunk_size_bytes: int = DEFAULT_CHUNK_SIZE,
        write_concern: Optional[WriteConcern] = None,
        read_preference: Optional[_ServerMode] = None,
    )

Source from the content-addressed store, hash-verified

460 """An instance of GridFS on top of a single Database."""
461
462 def __init__(
463 self,
464 db: Database[Any],
465 bucket_name: str = "fs",
466 chunk_size_bytes: int = DEFAULT_CHUNK_SIZE,
467 write_concern: Optional[WriteConcern] = None,
468 read_preference: Optional[_ServerMode] = None,
469 ) -> None:
470 """Create a new instance of :class:`GridFSBucket`.
471
472 Raises :exc:`TypeError` if `database` is not an instance of
473 :class:`~pymongo.database.Database`.
474
475 Raises :exc:`~pymongo.errors.ConfigurationError` if `write_concern`
476 is not acknowledged.
477
478 :param database: database to use.
479 :param bucket_name: The name of the bucket. Defaults to 'fs'.
480 :param chunk_size_bytes: The chunk size in bytes. Defaults
481 to 255KB.
482 :param write_concern: The
483 :class:`~pymongo.write_concern.WriteConcern` to use. If ``None``
484 (the default) db.write_concern is used.
485 :param read_preference: The read preference to use. If
486 ``None`` (the default) db.read_preference is used.
487
488 .. versionchanged:: 4.0
489 Removed the `disable_md5` parameter. See
490 :ref:`removed-gridfs-checksum` for details.
491
492 .. versionchanged:: 3.11
493 Running a GridFSBucket operation in a transaction now always raises
494 an error. GridFSBucket does not support multi-document transactions.
495
496 .. versionchanged:: 3.7
497 Added the `disable_md5` parameter.
498
499 .. versionadded:: 3.1
500
501 .. seealso:: The MongoDB documentation on `gridfs <https://dochub.mongodb.org/core/gridfs>`_.
502 """
503 if not isinstance(db, Database):
504 raise TypeError(f"database must be an instance of Database, not {type(db)}")
505
506 db = _clear_entity_type_registry(db)
507
508 wtc = write_concern if write_concern is not None else db.write_concern
509 if not wtc.acknowledged:
510 raise ConfigurationError("write concern must be acknowledged")
511
512 self._bucket_name = bucket_name
513 self._collection = db[bucket_name]
514 self._chunks: Collection[Any] = self._collection.chunks.with_options(
515 write_concern=write_concern, read_preference=read_preference
516 )
517
518 self._files: Collection[Any] = self._collection.files.with_options(
519 write_concern=write_concern, read_preference=read_preference

Callers

nothing calls this directly

Calls 3

ConfigurationErrorClass · 0.90
with_optionsMethod · 0.45

Tested by

no test coverage detected