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

Method delete

gridfs/asynchronous/grid_file.py:810–835  ·  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[AsyncClientSession] = None)

Source from the content-addressed store, hash-verified

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

Callers 2

Calls 4

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

Tested by 2