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

Method put

gridfs/synchronous/grid_file.py:129–157  ·  view source on GitHub ↗

Put data in GridFS as a new file. Equivalent to doing:: with fs.new_file(**kwargs) as f: f.write(data) `data` can be either an instance of :class:`bytes` or a file-like object providing a :meth:`read` method. If an `encoding` keyword argumen

(self, data: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

127 return GridIn(self._collection, **kwargs)
128
129 def put(self, data: Any, **kwargs: Any) -> Any:
130 """Put data in GridFS as a new file.
131
132 Equivalent to doing::
133
134 with fs.new_file(**kwargs) as f:
135 f.write(data)
136
137 `data` can be either an instance of :class:`bytes` or a file-like
138 object providing a :meth:`read` method. If an `encoding` keyword
139 argument is passed, `data` can also be a :class:`str` instance, which
140 will be encoded as `encoding` before being written. Any keyword
141 arguments will be passed through to the created file - see
142 :meth:`~gridfs.grid_file.GridIn` for possible arguments. Returns the
143 ``"_id"`` of the created file.
144
145 If the ``"_id"`` of the file is manually specified, it must
146 not already exist in GridFS. Otherwise
147 :class:`~gridfs.errors.FileExists` is raised.
148
149 :param data: data to be written as a file.
150 :param kwargs: keyword arguments for file creation
151
152 .. versionchanged:: 3.0
153 w=0 writes to GridFS are now prohibited.
154 """
155 with GridIn(self._collection, **kwargs) as grid_file:
156 grid_file.write(data)
157 return grid_file._id
158
159 def get(self, file_id: Any, session: Optional[ClientSession] = None) -> GridOut:
160 """Get a file from GridFS by ``"_id"``.

Callers 15

test_gridfs_secondaryMethod · 0.95
test_basicMethod · 0.45
test_listMethod · 0.45
test_empty_fileMethod · 0.45
test_corrupt_chunkMethod · 0.45
test_alt_collectionMethod · 0.45
test_threaded_readsMethod · 0.45
test_get_last_versionMethod · 0.45

Calls 2

GridInClass · 0.85
writeMethod · 0.45

Tested by 15

test_gridfs_secondaryMethod · 0.76
test_basicMethod · 0.36
test_listMethod · 0.36
test_empty_fileMethod · 0.36
test_corrupt_chunkMethod · 0.36
test_alt_collectionMethod · 0.36
test_threaded_readsMethod · 0.36
test_get_last_versionMethod · 0.36