Class yii\mongodb\file\Collection

Inheritanceyii\mongodb\file\Collection » yii\mongodb\Collection » yii\base\BaseObject
Implementsyii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2-mongodb/blob/master/file/Collection.php

Collection represents the Mongo GridFS collection information.

A file collection object is usually created by calling \yii\mongodb\file\Database::getFileCollection() or \yii\mongodb\file\Connection::getFileCollection().

File collection inherits all interface from regular \yii\mongo\Collection, adding methods to store files.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$database yii\mongodb\Database MongoDB database instance. yii\mongodb\file\Collection
$name string Name of this collection. yii\mongodb\Collection

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
aggregate() Performs aggregation using Mongo Aggregation Framework. yii\mongodb\Collection
batchInsert() Inserts several new rows into collection. yii\mongodb\Collection
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
count() Counts records in this collection. yii\mongodb\Collection
createDownload() Creates download command. yii\mongodb\file\Collection
createIndex() Creates an index on the collection and the specified fields. yii\mongodb\Collection
createIndexes() Creates several indexes at once. yii\mongodb\Collection
createUpload() Creates upload command. yii\mongodb\file\Collection
delete() Deletes the file with given _id. yii\mongodb\file\Collection
distinct() Returns a list of distinct values for the given column across a collection. yii\mongodb\Collection
documentExists() Returns if a document exists. yii\mongodb\Collection
drop() {@inheritdoc} yii\mongodb\file\Collection
dropAllIndexes() Drops all indexes for this collection. yii\mongodb\Collection
dropIndex() Drop indexes for specified column(s). yii\mongodb\Collection
dropIndexes() Drops collection indexes by name. yii\mongodb\Collection
ensureIndexes() Makes sure that indexes, which are crucial for the file processing, exist at this collection and \yii\mongodb\file\chunkCollection. yii\mongodb\file\Collection
find() {@inheritdoc} yii\mongodb\file\Collection
findAndModify() Updates a document and returns it. yii\mongodb\Collection
findOne() Returns a single document. yii\mongodb\Collection
get() Retrieves the file with given _id. yii\mongodb\file\Collection
getChunkCollection() Returns the MongoDB collection for the file chunks. yii\mongodb\file\Collection
getFileCollection() Returns the MongoDB collection for the files. yii\mongodb\file\Collection
getFullName() yii\mongodb\Collection
getPrefix() yii\mongodb\file\Collection
group() Performs aggregation using Mongo "group" command. yii\mongodb\Collection
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
insert() Inserts new data into collection. yii\mongodb\Collection
insertFile() Creates new file in GridFS collection from given local filesystem file. yii\mongodb\file\Collection
insertFileContent() Creates new file in GridFS collection with specified content. yii\mongodb\file\Collection
insertUploads() Creates new file in GridFS collection from uploaded file. yii\mongodb\file\Collection
listIndexes() Returns the list of defined indexes. yii\mongodb\Collection
mapReduce() Performs aggregation using MongoDB "map-reduce" mechanism. yii\mongodb\Collection
remove() {@inheritdoc} yii\mongodb\file\Collection
save() Update the existing database data, otherwise insert this data yii\mongodb\Collection
setPrefix() yii\mongodb\file\Collection
update() Updates the rows, which matches given criteria by given data. yii\mongodb\Collection

Property Details

$database public property

MongoDB database instance.

Method Details

createDownload() public method (available since version 2.1)

Creates download command.

public yii\mongodb\file\Download createDownload ( $document )
$document array|\MongoDB\BSON\ObjectID

File document ot be downloaded.

return yii\mongodb\file\Download

File download instance.

createUpload() public method (available since version 2.1)

Creates upload command.

public yii\mongodb\file\Upload createUpload ( $options = [] )
$options array

Upload options.

return yii\mongodb\file\Upload

File upload instance.

delete() public method

Deletes the file with given _id.

public boolean delete ( $id )
$id mixed

_id of the file to find.

return boolean

Whether the operation was successful.

throws yii\mongodb\Exception

on failure.

drop() public method

{@inheritdoc}

public void drop ( )
ensureIndexes() public method

Makes sure that indexes, which are crucial for the file processing, exist at this collection and \yii\mongodb\file\chunkCollection.

The check result is cached per collection instance.

public $this ensureIndexes ( $force false )
$force boolean

Whether to ignore internal collection instance cache.

return $this

Self reference.

find() public method

{@inheritdoc}

public yii\mongodb\file\Cursor find ( $condition = [], $fields = [], $options = [] )
$condition
$fields
$options
return yii\mongodb\file\Cursor

Cursor for the search results

get() public method

Retrieves the file with given _id.

public yii\mongodb\file\Download|null get ( $id )
$id mixed

_id of the file to find.

return yii\mongodb\file\Download|null

Found file, or null if file does not exist

throws yii\mongodb\Exception

on failure.

getChunkCollection() public method

Returns the MongoDB collection for the file chunks.

public yii\mongodb\Collection getChunkCollection ( $refresh false )
$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 (available since version 2.1)

Returns the MongoDB collection for the files.

public yii\mongodb\Collection getFileCollection ( $refresh false )
$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 string getPrefix ( )
return string

Prefix of this file collection.

insertFile() public method

Creates new file in GridFS collection from given local filesystem file.

Additional attributes can be added file document using $metadata.

public mixed insertFile ( $filename, $metadata = [], $options = [] )
$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.

throws yii\mongodb\Exception

on failure.

insertFileContent() public method

Creates new file in GridFS collection with specified content.

Additional attributes can be added file document using $metadata.

public mixed insertFileContent ( $bytes, $metadata = [], $options = [] )
$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.

throws yii\mongodb\Exception

on failure.

insertUploads() public method

Creates new file in GridFS collection from uploaded file.

Additional attributes can be added file document using $metadata.

public mixed insertUploads ( $name, $metadata = [], $options = [] )
$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.

throws yii\mongodb\Exception

on failure.

remove() public method

{@inheritdoc}

public void remove ( $condition = [], $options = [] )
$condition
$options
setPrefix() public method

public void setPrefix ( $prefix )
$prefix string

Prefix of this file collection.