文档菜单
文档首页
/ / /
PHP 库手册
/ /

MongoDB\GridFS\Bucket::delete()

本页内容

  • 定义
  • 参数
  • 错误/异常
  • 行为
  • 示例
MongoDB\GridFS\Bucket::delete()

从GridFS桶中删除文件及其块。

function delete($id): void
$id : 混合类型
要删除的文件的_id

如果没有找到符合选择条件的文件,则会出现MongoDB\GridFS\Exception\FileNotFoundException

对于扩展级别的其他错误(例如连接错误),请参阅MongoDB\Driver\Exception\RuntimeException

如果未找到文件集合文档,此方法仍将尝试删除孤立的块。

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

返回

__construct()