PHP Class yii\mongodb\file\Collection

A file collection object is usually created by calling [[Database::getFileCollection()]] or [[Connection::getFileCollection()]]. File collection inherits all interface from regular [[\yii\mongo\Collection]], adding methods to store files.
Since: 2.0
Author: Paul Klimov ([email protected])
Inheritance: extends yii\mongodb\Collection
Datei anzeigen Open project: yiisoft/yii2-mongodb Class Usage Examples

Public Properties

Property Type Description
$database MongoDB database instance.

Public Methods

Method Description
createDownload ( array | MongoDB\BSON\ObjectID $document ) : Download Creates download command.
createUpload ( array $options = [] ) : Upload Creates upload command.
delete ( mixed $id ) : boolean Deletes the file with given _id.
drop ( )
ensureIndexes ( boolean $force = false ) Makes sure that indexes, which are crucial for the file processing, exist at this collection and [[chunkCollection]].
find ( $condition = [], $fields = [], $options = [] ) : Cursor
get ( mixed $id ) : Download | null Retrieves the file with given _id.
getChunkCollection ( boolean $refresh = false ) : Collection Returns the MongoDB collection for the file chunks.
getFileCollection ( boolean $refresh = false ) : Collection Returns the MongoDB collection for the files.
getPrefix ( ) : string
insertFile ( string $filename, array $metadata = [], array $options = [] ) : mixed Creates new file in GridFS collection from given local filesystem file.
insertFileContent ( string $bytes, array $metadata = [], array $options = [] ) : mixed Creates new file in GridFS collection with specified content.
insertUploads ( string $name, array $metadata = [], array $options = [] ) : mixed Creates new file in GridFS collection from uploaded file.
remove ( $condition = [], $options = [] )
setPrefix ( string $prefix )

Private Methods

Method Description
ensureChunkIndexes ( ) Ensures indexes at chunk collection.
ensureFileIndexes ( ) Ensures indexes at file collection.

Method Details

createDownload() public method

Creates download command.
Since: 2.1
public createDownload ( array | MongoDB\BSON\ObjectID $document ) : Download
$document array | MongoDB\BSON\ObjectID file document ot be downloaded.
return Download file download instance.

createUpload() public method

Creates upload command.
Since: 2.1
public createUpload ( array $options = [] ) : Upload
$options array upload options.
return Upload file upload instance.

delete() public method

Deletes the file with given _id.
public delete ( mixed $id ) : boolean
$id mixed _id of the file to find.
return boolean whether the operation was successful.

drop() public method

public drop ( )

ensureIndexes() public method

The check result is cached per collection instance.
public ensureIndexes ( boolean $force = false )
$force boolean whether to ignore internal collection instance cache.

find() public method

public find ( $condition = [], $fields = [], $options = [] ) : Cursor
return Cursor cursor for the search results

get() public method

Retrieves the file with given _id.
public get ( mixed $id ) : Download | null
$id mixed _id of the file to find.
return Download | null found file, or null if file does not exist

getChunkCollection() public method

Returns the MongoDB collection for the file chunks.
public getChunkCollection ( boolean $refresh = false ) : Collection
$refresh boolean whether to reload the collection instance even if it is found in the cache.
return yii\mongodb\Collection mongo collection instance.

getFileCollection() public method

Returns the MongoDB collection for the files.
Since: 2.1
public getFileCollection ( boolean $refresh = false ) : Collection
$refresh boolean whether to reload the collection instance even if it is found in the cache.
return yii\mongodb\Collection mongo collection instance.

getPrefix() public method

public getPrefix ( ) : string
return string prefix of this file collection.

insertFile() public method

Additional attributes can be added file document using $metadata.
public insertFile ( string $filename, array $metadata = [], array $options = [] ) : mixed
$filename string name of the file to store.
$metadata array other metadata fields to include in the file document.
$options array list of options in format: optionName => optionValue
return mixed the "_id" of the saved file document. This will be a generated [[\MongoId]] unless an "_id" was explicitly specified in the metadata.

insertFileContent() public method

Additional attributes can be added file document using $metadata.
public insertFileContent ( string $bytes, array $metadata = [], array $options = [] ) : mixed
$bytes string string of bytes to store.
$metadata array other metadata fields to include in the file document.
$options array list of options in format: optionName => optionValue
return mixed the "_id" of the saved file document. This will be a generated [[\MongoId]] unless an "_id" was explicitly specified in the metadata.

insertUploads() public method

Additional attributes can be added file document using $metadata.
public insertUploads ( string $name, array $metadata = [], array $options = [] ) : mixed
$name string name of the uploaded file to store. This should correspond to the file field's name attribute in the HTML form.
$metadata array other metadata fields to include in the file document.
$options array list of options in format: optionName => optionValue
return mixed the "_id" of the saved file document. This will be a generated [[\MongoId]] unless an "_id" was explicitly specified in the metadata.

remove() public method

public remove ( $condition = [], $options = [] )

setPrefix() public method

public setPrefix ( string $prefix )
$prefix string prefix of this file collection.

Property Details

$database public_oe property

MongoDB database instance.
public $database