|
The MongoGridFS class(Информация о версии неизвестна, возможно, только в SVN) ВведениеUtilities for storing and retrieving files from the database. GridFS is a storage specification all supported drivers implement. Basically, it defines two collections: files, for file metadata, and chunks, for file content. If the file is large, it will automatically be split into smaller chunks and each chunk will be saved as a document in the chunks collection. Each document in the files collection contains the filename, upload date, and md5 hash. It also contains a unique _id field, which can be used to query the chunks collection for the file's content. Each document in the chunks collection contains a chunk of binary data, a files_id field that matches its file's _id, and the position of this chunk in the overall file. For example, the files document is something like:
<?php
<?php Inter-Language CompatibilityYou should be able to use any files created by MongoGridFS with any other drivers, and visa vera. However, some drivers expect that all metadata associated with a file be in a "metadata" field. If you're going to be using other languages, it's a good idea to wrap info you might want them to see in a "metadata" field. For example, instead of:
<?php use something like:
<?php The MongoGridFS FamilyMongoGridFS 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:
<?php Another example of manipulating metadata:
<?php You can also access the chunks collection from an instance of MongoGridFS:
<?php There are some methods for MongoGridFS with the same name as MongoCollection methods, that behave slightly differently. For example, MongoGridFS::remove() will remove any objects that match the criteria from the files collection and their content from the chunks collection. To store something new in GridFS, there are a couple options. If you have a filename, you can say:
<?php If you have a string of bytes that isn't a file, you can also store that using MongoGridFS::storeBytes():
<?php 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 MongoGridFSFile::write() or retrieved in memory using MongoGridFSFile::getBytes(). There is currently no method that automatically streams chunks, but it would be fairly easy to write by querying the $grid->chunks collection. MongoGridFSFile objects contain a field file which contains any file metadata. Обзор классов
extends
MongoCollection
{
/* Fields */
protected
string
$filesName
= NULL
;
protected
string
$chunksName
= NULL
;
/* Методы */
public MongoGridFSCursor MongoGridFS::find
([ array $query = array()
[, array $fields = array()
]] )
public MongoGridFSFile MongoGridFS::findOne
([ mixed $query = array()
[, mixed $fields = array()
]] )
public mixed MongoGridFS::storeBytes
( string $bytes
[, array $extra = array()
[, array $options = array()
]] )
public mixed MongoGridFS::storeFile
( string $filename
[, array $extra = array()
[, array $options = array()
]] )
}Смотрите такжеMongoDB core docs on » GridFS. There's also a nice intro to » saving user uploads and » adding metadata at LightCubeSolutions.com. Содержание
|
|