1
1
<?php
2
- require 'vendor/autoload.php ' ; // include Composer's autoloader
2
+ require 'vendor/autoload.php ' ;
3
3
4
4
use MongoDB \Client ;
5
- use MongoDB \BSON \ObjectID ;
6
- use MongoDB \GridFS \Bucket ;
7
- use MongoDB \Driver \Manager ;
5
+ use MongoDB \BSON \ObjectId ;
8
6
9
7
$ uri = getenv ('MONGODB_URI ' ) ?: throw new RuntimeException ('Set the MONGODB_URI variable to your Atlas URI that connects to the sample dataset ' );
10
- $ client = new MongoDB \ Client ($ uri );
8
+ $ client = new Client ($ uri );
11
9
12
10
// start-to-json
13
11
function toJSON (object $ document ): string
@@ -59,9 +57,9 @@ function toJSON(object $document): string
59
57
fclose ($ stream );
60
58
// end-open-download-stream-name
61
59
62
- // Downloads a file from the GridFS bucket by referencing its ObjectID value
60
+ // Downloads a file from the GridFS bucket by referencing its ObjectId value
63
61
// start-download-files-id
64
- $ stream = $ bucket ->openDownloadStream (new ObjectID ('66e0a5487c880f844c0a32b1 ' ));
62
+ $ stream = $ bucket ->openDownloadStream (new ObjectId ('66e0a5487c880f844c0a32b1 ' ));
65
63
$ contents = stream_get_contents ($ stream );
66
64
fclose ($ stream );
67
65
// end-download-files-id
@@ -75,19 +73,19 @@ function toJSON(object $document): string
75
73
76
74
// Downloads an entire GridFS file to a download stream
77
75
// start-download-to-stream
78
- $ stream = fopen ('/path/to/output_file ' , 'wb ' );
76
+ $ file = fopen ('/path/to/output_file ' , 'wb ' );
79
77
$ bucket ->downloadToStream (
80
- new ObjectID ('66e0a5487c880f844c0a32b1 ' ),
81
- $ stream ,
78
+ new ObjectId ('66e0a5487c880f844c0a32b1 ' ),
79
+ $ file ,
82
80
);
83
81
// end-download-to-stream
84
82
85
- // Renames a file from the GridFS bucket with the specified ObjectID
83
+ // Renames a file from the GridFS bucket with the specified ObjectId
86
84
// start-rename-files
87
- $ bucket ->rename (new ObjectID ('66e0a5487c880f844c0a32b1 ' ), 'new_file_name ' );
85
+ $ bucket ->rename (new ObjectId ('66e0a5487c880f844c0a32b1 ' ), 'new_file_name ' );
88
86
// end-rename-files
89
87
90
- // Deletes a file from the GridFS bucket with the specified ObjectID
88
+ // Deletes a file from the GridFS bucket with the specified ObjectId
91
89
// start-delete-files
92
- $ bucket ->delete (new ObjectID ('66e0a5487c880f844c0a32b1 ' ));
90
+ $ bucket ->delete (new ObjectId ('66e0a5487c880f844c0a32b1 ' ));
93
91
// end-delete-files
0 commit comments