I'm trying to make a log system using mongodb in php and GridFS. I can initially write data to my file but once I close the stream I don't know how to append data later to it. This is how I write to it:
$bucket= DB::connection('mongodb')->getMongoDB()->selectGridFSBucket();
$stream = $bucket->openUploadStream('my-file-name.txt');
$contents = 'whatever text here
';
fwrite($stream, $contents);
fclose($stream);
I tried retreiving it and appending data to the stream but it doesn't work. This is attempt:
$bucket= DB::connection('mongodb')->getMongoDB()->selectGridFSBucket();
$stream = $bucket->openDownloadStreamByName('my-file-name.txt');
fwrite($stream, $contents);
also tried fopen
on the stream but no luck. I also don't know how to retrieve this file Id after writing data to it.