php data grid,PHP - Manual: MongoGridFS (官方文档)

The MongoGridFS Family

MongoGridFS represents the files and chunks

collections. MongoGridFS extends MongoCollection,

and an instance of MongoGridFS has access to all of

MongoCollection methods, which act on the files

collection:

$grid=$db->getGridFS();$grid->update(array("filename"=>"foo"),$newObj);// update on the files collection?>

Another example of manipulating metadata:

<?php // save a file$id=$grid->storeFile("game.tgz");$game=$grid->findOne();// add a downloads counter$game->file['downloads'] =0;$grid->save($game->file);// increment the counter$grid->update(array("_id"=>$id), array('$inc'=> array("downloads"=>1)));?>

You can also access the chunks collection from an instance of

MongoGridFS:

$chunks=$grid->chunks;// $chunks is a normal MongoCollection$chunks->insert(array("x"=>4));?>

There are some methods for MongoGridFS with the same

name as MongoCollection methods, that behave

slightly differently. For example,

To store something new in GridFS, there are a couple options. If you have

a filename, you can say:

$grid->storeFile($filename, array("whatever"=>"metadata","you"=>"want"));?>

If you have a string of bytes that isn't a file, you can also store that

using

$grid->storeBytes($bytes, array("whatever"=>"metadata","you"=>"want"));?>

Querying a MongoGridFS collection returns a

MongoGridFSCursor, which behaves like a normal

MongoCursor except that it returns

MongoGridFSFiles instead of associative arrays.

MongoGridFSFiles can be written back to disc using

$grid->chunks collection.

MongoGridFSFile objects contain a field file which

contains any file metadata.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值