ANNOUNCEMENT: Voyage AI joins MongoDB to power more accurate and trustworthy AI applications on Atlas.
Learn more
Docs Menu

MongoDB\GridFS\Bucket::rename()

MongoDB\GridFS\Bucket::rename()

_id 기준으로 GridFS 파일 을 선택하고 filename 을(를) 변경합니다.

function rename($id, string $newFilename): void
$id : 혼합
이름을 바꿀 파일 의 _id 입니다.
$newFilename : 문자열
filename 값입니다.

선택 기준에 맞는 파일 을 찾을 수 없는 경우 MongoDB\GridFS\Exception\FileNotFoundException 를 반환합니다.

MongoDB\ 드라이버\Exception\RuntimeException 확장 수준의 다른 오류(예: 연결 오류).

<?php
$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')));

이 경우 출력은 다음과 유사합니다:

string(6) "foobar"