You are viewing an offline version of MongoDB documentation. Some page features might be unavailable. To view the latest version of the page or use interactive features, visit the live page.
MongoDB\GridFS\Bucket::rename()
Definition
Parameters
$id: mixed- The
_idof the file to rename. $newFilename: string- The new
filenamevalue.
Errors/Exceptions
MongoDB\GridFS\Exception\FileNotFoundException if no file was
found for the selection criteria.
MongoDB\Driver\Exception\RuntimeException for other errors at the extension level (e.g. connection errors).
Examples
$bucket = (new MongoDB\Client)->test->selectGridFSBucket(); $stream = fopen('php://temp', 'w+b'); fwrite($stream, "foobar"); rewind($stream); $id = $bucket->uploadFromStream('a', $stream); $bucket->rename($id, 'b'); var_dump(stream_get_contents($bucket->openDownloadStreamByName('b')));
The output would then resemble:
string(6) "foobar"