W3cubDocs

/Yii 2.0

Class yii\mongodb\file\Collection

Inheritance yii\mongodb\file\Collection » yii\mongodb\Collection » yii\base\Object
Implements yii\base\Configurable
Available since version 2.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

Property Type Description Defined By
$chunkCollection yii\mongodb\Collection Mongo collection instance. yii\mongodb\file\Collection
$database yii\mongodb\Database MongoDB database instance. yii\mongodb\file\Collection
$fileCollection yii\mongodb\Collection Mongo collection instance. yii\mongodb\file\Collection
$fullName string Full name of this collection, including database name. yii\mongodb\Collection
$name string Name of this collection. yii\mongodb\Collection
$prefix string Prefix of this file collection. yii\mongodb\file\Collection

Public Methods

Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\Object
__construct() Constructor. yii\base\Object
__get() Returns the value of an object property. yii\base\Object
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Object
__set() Sets value of an object property. yii\base\Object
__unset() Sets an object property to null. yii\base\Object
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\Object
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Object
className() Returns the fully qualified name of this class. yii\base\Object
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
drop() Drops this collection. 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 $chunkCollection. yii\mongodb\file\Collection
find() Returns a cursor for the search results. 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\Object
hasProperty() Returns a value indicating whether a property is defined. yii\base\Object
init() Initializes the object. yii\base\Object
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() Removes data from the collection. 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

$chunkCollection public read-only property

Mongo collection instance.

public yii\mongodb\Collection getChunkCollection ( $refresh = false )

$database public property

MongoDB database instance.

public yii\mongodb\Database $database = null

$fileCollection public read-only property

Mongo collection instance.

public yii\mongodb\Collection getFileCollection ( $refresh = false )

$prefix public property

Prefix of this file collection.

public string getPrefix ( )
public void setPrefix ( $prefix )

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

Drops this collection.

public boolean drop ( )
return boolean

Whether the operation successful.

throws yii\mongodb\Exception

on failure.

ensureIndexes() public method

Makes sure that indexes, which are crucial for the file processing, exist at this collection and $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

Returns a cursor for the search results.

In order to perform "find" queries use yii\mongodb\file\Query class.

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

Query condition

$fields array

Fields to be selected

$options array

Query options (available since 2.1).

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

Removes data from the collection.

public integer|boolean remove ( $condition = [], $options = [] )
$condition array

Description of records to remove.

$options array

List of options in format: optionName => optionValue.

return integer|boolean

Number of updated documents or whether operation was successful.

throws yii\mongodb\Exception

on failure.

setPrefix() public method

public void setPrefix ( $prefix )
$prefix string

Prefix of this file collection.

© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-mongodb-file-collection.html