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