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

Method delete

gridfs/synchronous/grid_file.py:806–831  ·  view source on GitHub ↗

Given an file_id, delete this stored file's files collection document and associated chunks from a GridFS bucket. For example:: my_db = MongoClient().test fs = GridFSBucket(my_db) # Get _id of file to delete file_id = fs.upload_from_stream("t

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

Source from the content-addressed store, hash-verified

804
805 @_csot.apply
806 def delete(self, file_id: Any, session: Optional[ClientSession] = None) -> None:
807 """Given an file_id, delete this stored file's files collection document
808 and associated chunks from a GridFS bucket.
809
810 For example::
811
812 my_db = MongoClient().test
813 fs = GridFSBucket(my_db)
814 # Get _id of file to delete
815 file_id = fs.upload_from_stream("test_file", "data I want to store!")
816 fs.delete(file_id)
817
818 Raises :exc:`~gridfs.errors.NoFile` if no file with file_id exists.
819
820 :param file_id: The _id of the file to be deleted.
821 :param session: a
822 :class:`~pymongo.client_session.ClientSession`
823
824 .. versionchanged:: 3.6
825 Added ``session`` parameter.
826 """
827 _disallow_transactions(session)
828 res = self._files.delete_one({"_id": file_id}, session=session)
829 self._chunks.delete_many({"files_id": file_id}, session=session)
830 if not res.deleted_count:
831 raise NoFile("no file could be deleted because none matched %s" % file_id)
832
833 @_csot.apply
834 def delete_by_name(self, filename: str, session: Optional[ClientSession] = None) -> None:

Callers 2

Calls 4

NoFileClass · 0.90
_disallow_transactionsFunction · 0.70
delete_oneMethod · 0.45
delete_manyMethod · 0.45

Tested by 2