2017 © Pedro Peláez
 

library gridfs-update

Library to make mongo gridfs in-place updates

image

gaillard/gridfs-update

Library to make mongo gridfs in-place updates

  • Tuesday, July 29, 2014
  • by gaillard
  • Repository
  • 1 Watchers
  • 1 Stars
  • 279 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

gridfs-update-php

Build Status, (*1)

Library to make mongo gridfs in-place updates, (*2)

Requirements

Requires PHP 5.4.0 (or later)., (*3)

Installation

To add the library as a local, per-project dependency use Composer!, (*4)

{
    "require": {
        "gaillard/gridfs-update": "~1.0"
    }
}

Example

$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";

prints, (*5)

metadata is array(3) {
  'key1' =>
  string(5) "Hello"
  'key2' =>
  string(3) "Mr."
  'key3' =>
  string(5) "Smith"
}
bytes are 123456
metadata is now array(2) {
  'key1' =>
  string(5) "Hello"
  'key2' =>
  string(3) "Bob"
}
bytes are now 7890

Which has updated the chunks without removing them (unless there are extra) and the file doc as well. Primary benefit is speed. Please be aware of any side effects in your system for concurrent access. The mongo-lock-php library could help!, (*6)

Contributing

If you would like to contribute, please use the build process for any changes and after the build passes, send a pull request on github!, (*7)

./build.php

The Versions

29/07 2014

dev-master

9999999-dev

Library to make mongo gridfs in-place updates

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-mongo ~1.3

 

The Development Requires

mongo gridfs

29/07 2014

v1.0.0

1.0.0.0

Library to make mongo gridfs in-place updates

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-mongo ~1.3

 

The Development Requires

mongo gridfs