For AI agents: a documentation index is available at https://www.mongodb.com/pt-br/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
See how MongoDB 9.0 delivers up to 2x higher throughput.
MongoDB Branding Shape
Register now >
Docs Menu

MongoDB\GridFS\Bucket::getFileDocumentForStream()

MongoDB\GridFS\Bucket::getFileDocumentForStream()

Gets the file document of the GridFS file associated with a stream.

function getFileDocumentForStream(resource $stream): array|object
$stream : resource
The GridFS stream resource.

The metadata document associated with the GridFS stream. The return type will depend on the bucket's typeMap option.

MongoDB\Exception\InvalidArgumentException for errors related to the parsing of parameters or options.

MongoDB\Driver\Exception\RuntimeException for other errors at the extension level (e.g. connection errors).

<?php
$bucket = (new MongoDB\Client)->test->getGridFSBucket();
$stream = $bucket->openUploadStream('filename');
$fileDocument = $bucket->getFileDocumentForStream($stream);
var_dump($fileDocument);
fclose($stream);

The output would then resemble:

object(MongoDB\Model\BSONDocument)#4956 (1) {
["storage":"ArrayObject":private]=>
array(3) {
["_id"]=>
object(MongoDB\BSON\ObjectId)#4955 (1) {
["oid"]=>
string(24) "5acfb05b7e21e83b5a29037c"
}
["chunkSize"]=>
int(261120)
["filename"]=>
string(8) "filename"
}
}