Docs Menu

MongoDB\GridFS\Bucket::delete()

MongoDB\GridFS\Bucket::delete()

GridFS 버킷에서 파일과 해당 청크를 삭제합니다.

function delete($id): void
$id : 혼합
삭제할 파일의 _id 입니다.

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

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

파일 collection 문서를 찾을 수 없는 경우에도 이 메서드는 여전히 분리된 청크를 삭제하려고 시도합니다.

<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = fopen('php://temp', 'w+b');
fwrite($stream, "foobar");
rewind($stream);
$id = $bucket->uploadFromStream('filename', $stream);
$bucket->delete($id);