yii\mongodb\file\Collection - Yii2 类参考手册

Class yii\mongodb\file\Collection

Inheritanceyii\mongodb\file\Collection » yii\mongodb\Collection » yii\base\BaseObject
Implementsyii\base\Configurable
Available since version2.0

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

属性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

隐藏继承的方法 Hide inherited methods

方法 Method简介 Description定义在 Defined 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
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\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() 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.

$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.