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

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