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

Class GridFSBucket

gridfs/synchronous/grid_file.py:459–1072  ·  view source on GitHub ↗

An instance of GridFS on top of a single Database.

Source from the content-addressed store, hash-verified

457
458
459class GridFSBucket:
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 )

Callers 9

test_gridfs_bucketMethod · 0.90
_create_entityMethod · 0.90
setUpMethod · 0.90
insert_gridfs_fileFunction · 0.90
read_gridfs_fileFunction · 0.90
beforeMethod · 0.90
setUpMethod · 0.90

Calls

no outgoing calls

Tested by 8

test_gridfs_bucketMethod · 0.72
setUpMethod · 0.72
insert_gridfs_fileFunction · 0.72
read_gridfs_fileFunction · 0.72
beforeMethod · 0.72
setUpMethod · 0.72