gaillard/gridfs-update
Composer 安装命令:
composer require gaillard/gridfs-update
包简介
Library to make mongo gridfs in-place updates
README 文档
README
Library to make mongo gridfs in-place updates
Requirements
Requires PHP 5.4.0 (or later).
Installation
To add the library as a local, per-project dependency use Composer!
{
"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
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!
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!
./build.php
统计信息
- 总下载量: 284
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-07-29