For AI agents: a documentation index is available at https://www.mongodb.com/ja-jp/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs Menu

MongoDB\GridFS\Bucket::deleteByName()

MongoDB\GridFS\Bucket::deleteByName()

Deletes a file and all its revisions from the GridFS bucket.

function deleteByName(string $filename): void
$filename : string
The filename of the files to delete.

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).

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