This version of the documentation is archived and no longer supported. To learn how to upgrade your version of PHP Library Manual, refer to the upgrade documentation.




Selects a GridFS file by its _id and copies its contents to a writable stream.

function downloadToStream($id, $destination): void

This method has the following parameters:

Parameter Type Description
$id mixed The _id of the file.
$destination resource Writable stream, to which the GridFS file’s contents will be written.


MongoDB\GridFS\Exception\FileNotFoundException if no file was found for the selection criteria.

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

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