1. Go to this page and download the library: Download gaillard/gridfs-update library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gaillard / gridfs-update example snippets
$id = new \MongoId();
$gridfs = (new \MongoClient())->selectDB('gridfsUpdaterExample')->getGridFS();
$gridfs->storeBytes('123456', ['_id' => $id, 'metadata' => ['key1' => 'Hello', 'key2' => 'Mr.', 'key3' => 'Smith']]);
$before = $gridfs->findOne();
echo 'metadata is ';
var_dump($before->file['metadata']);
echo "bytes are {$before->getBytes()}\n";
GridFsUpdater::update(
$gridfs,
$id,
'7890',
[
'$set' => ['metadata.key2' => 'Bob'],
'$unset' => ['metadata.key3' => ''],
]
);
$after = $gridfs->findOne();
echo 'metadata is now ';
var_dump($after->file['metadata']);
echo "bytes are now {$after->getBytes()}\n";
sh
./build.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.