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

Method delete

gridfs/synchronous/grid_file.py:260–286  ·  view source on GitHub ↗

Delete a file from GridFS by ``"_id"``. Deletes all data belonging to the file with ``"_id"``: `file_id`. .. warning:: Any processes/threads reading from the file while this method is executing will likely see an invalid/corrupt file. Care should be ta

(self, file_id: Any, session: Optional[ClientSession] = None)

Source from the content-addressed store, hash-verified

258
259 # TODO add optional safe mode for chunk removal?
260 def delete(self, file_id: Any, session: Optional[ClientSession] = None) -> None:
261 """Delete a file from GridFS by ``"_id"``.
262
263 Deletes all data belonging to the file with ``"_id"``:
264 `file_id`.
265
266 .. warning:: Any processes/threads reading from the file while
267 this method is executing will likely see an invalid/corrupt
268 file. Care should be taken to avoid concurrent reads to a file
269 while it is being deleted.
270
271 .. note:: Deletes of non-existent files are considered successful
272 since the end result is the same: no file with that _id remains.
273
274 :param file_id: ``"_id"`` of the file to delete
275 :param session: a
276 :class:`~pymongo.client_session.ClientSession`
277
278 .. versionchanged:: 3.6
279 Added ``session`` parameter.
280
281 .. versionchanged:: 3.1
282 ``delete`` no longer ensures indexes.
283 """
284 _disallow_transactions(session)
285 self._files.delete_one({"_id": file_id}, session=session)
286 self._chunks.delete_many({"files_id": file_id}, session=session)
287
288 def list(self, session: Optional[ClientSession] = None) -> list[str]:
289 """List the names of all files stored in this instance of

Callers 1

Calls 3

_disallow_transactionsFunction · 0.70
delete_oneMethod · 0.45
delete_manyMethod · 0.45

Tested by 1