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

Method rename

gridfs/asynchronous/grid_file.py:1020–1051  ·  view source on GitHub ↗

Renames the stored file with the specified file_id. For example:: my_db = MongoClient().test fs = GridFSBucket(my_db) # Get _id of file to rename file_id = fs.upload_from_stream("test_file", "data I want to store!") fs.rename(file_id, "new_

(
        self, file_id: Any, new_filename: str, session: Optional[AsyncClientSession] = None
    )

Source from the content-addressed store, hash-verified

1018 destination.write(chunk)
1019
1020 async def rename(
1021 self, file_id: Any, new_filename: str, session: Optional[AsyncClientSession] = None
1022 ) -> None:
1023 """Renames the stored file with the specified file_id.
1024
1025 For example::
1026
1027 my_db = MongoClient().test
1028 fs = GridFSBucket(my_db)
1029 # Get _id of file to rename
1030 file_id = fs.upload_from_stream("test_file", "data I want to store!")
1031 fs.rename(file_id, "new_test_name")
1032
1033 Raises :exc:`~gridfs.errors.NoFile` if no file with file_id exists.
1034
1035 :param file_id: The _id of the file to be renamed.
1036 :param new_filename: The new name of the file.
1037 :param session: a
1038 :class:`~pymongo.client_session.AsyncClientSession`
1039
1040 .. versionchanged:: 3.6
1041 Added ``session`` parameter.
1042 """
1043 _disallow_transactions(session)
1044 result = await self._files.update_one(
1045 {"_id": file_id}, {"$set": {"filename": new_filename}}, session=session
1046 )
1047 if not result.matched_count:
1048 raise NoFile(
1049 "no files could be renamed %r because none "
1050 "matched file_id %i" % (new_filename, file_id)
1051 )
1052
1053 async def rename_by_name(
1054 self, filename: str, new_filename: str, session: Optional[AsyncClientSession] = None

Callers

nothing calls this directly

Calls 3

NoFileClass · 0.90
_disallow_transactionsFunction · 0.70
update_oneMethod · 0.45

Tested by

no test coverage detected