MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / GridIn

Class GridIn

gridfs/synchronous/grid_file.py:1075–1435  ·  view source on GitHub ↗

Class to write data to GridFS.

Source from the content-addressed store, hash-verified

1073
1074
1075class GridIn:
1076 """Class to write data to GridFS."""
1077
1078 def __init__(
1079 self,
1080 root_collection: Collection[Any],
1081 session: Optional[ClientSession] = None,
1082 **kwargs: Any,
1083 ) -> None:
1084 """Write a file to GridFS
1085
1086 Application developers should generally not need to
1087 instantiate this class directly - instead see the methods
1088 provided by :class:`~gridfs.GridFS`.
1089
1090 Raises :class:`TypeError` if `root_collection` is not an
1091 instance of :class:`~pymongo.collection.Collection`.
1092
1093 Any of the file level options specified in the `GridFS Spec
1094 <http://dochub.mongodb.org/core/gridfsspec>`_ may be passed as
1095 keyword arguments. Any additional keyword arguments will be
1096 set as additional fields on the file document. Valid keyword
1097 arguments include:
1098
1099 - ``"_id"``: unique ID for this file (default:
1100 :class:`~bson.objectid.ObjectId`) - this ``"_id"`` must
1101 not have already been used for another file
1102
1103 - ``"filename"``: human name for the file
1104
1105 - ``"contentType"`` or ``"content_type"``: valid mime-type
1106 for the file
1107
1108 - ``"chunkSize"`` or ``"chunk_size"``: size of each of the
1109 chunks, in bytes (default: 255 kb)
1110
1111 - ``"encoding"``: encoding used for this file. Any :class:`str`
1112 that is written to the file will be converted to :class:`bytes`.
1113
1114 :param root_collection: root collection to write to
1115 :param session: a
1116 :class:`~pymongo.client_session.ClientSession` to use for all
1117 commands
1118 :param kwargs: Any: file level options (see above)
1119
1120 .. versionchanged:: 4.0
1121 Removed the `disable_md5` parameter. See
1122 :ref:`removed-gridfs-checksum` for details.
1123
1124 .. versionchanged:: 3.7
1125 Added the `disable_md5` parameter.
1126
1127 .. versionchanged:: 3.6
1128 Added ``session`` parameter.
1129
1130 .. versionchanged:: 3.0
1131 `root_collection` must use an acknowledged
1132 :attr:`~pymongo.collection.Collection.write_concern`

Callers 15

test_basicMethod · 0.90
test_md5Method · 0.90
test_write_file_likeMethod · 0.90
test_write_linesMethod · 0.90
test_closeMethod · 0.90
test_closedMethod · 0.90

Calls 1

_grid_in_propertyFunction · 0.90

Tested by 15

test_basicMethod · 0.72
test_md5Method · 0.72
test_write_file_likeMethod · 0.72
test_write_linesMethod · 0.72
test_closeMethod · 0.72
test_closedMethod · 0.72