forked from mongodb/docs-php-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMongoDBGridFSBucket-getFileDocumentForStream.txt
80 lines (54 loc) · 1.63 KB
/
MongoDBGridFSBucket-getFileDocumentForStream.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
===================================================
MongoDB\\GridFS\\Bucket::getFileDocumentForStream()
===================================================
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. phpmethod:: MongoDB\GridFS\Bucket::getFileDocumentForStream()
Gets the file document of the GridFS file associated with a stream.
.. code-block:: php
function getFileDocumentForStream(resource $stream): array|object
Parameters
----------
``$stream`` : resource
The GridFS stream resource.
Return Values
-------------
The metadata document associated with the GridFS stream. The return type will
depend on the bucket's ``typeMap`` option.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst
Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = $bucket->openUploadStream('filename');
$fileDocument = $bucket->getFileDocumentForStream($stream);
var_dump($fileDocument);
fclose($stream);
The output would then resemble:
.. code-block:: none
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"
}
}
See Also
--------
- :phpmethod:`MongoDB\GridFS\Bucket::getFileIdForStream()`