Class yii\mongodb\file\Collection
Inheritance | yii\mongodb\file\Collection » yii\mongodb\Collection » yii\base\Object |
---|---|
Available since version | 2.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
Property | Type | Description | Defined By |
---|---|---|---|
$mongoCollection | \MongoGridFS | Mongo GridFS collection instance. | yii\mongodb\file\Collection |
Public Methods
Method | Description | Defined By |
---|---|---|
aggregate() | Performs aggregation using Mongo Aggregation Framework. | yii\mongodb\Collection |
batchInsert() | Inserts several new rows into collection. | yii\mongodb\Collection |
buildAndCondition() | Connects two or more conditions with the AND operator. |
yii\mongodb\Collection |
buildBetweenCondition() | Creates an Mongo condition, which emulates the BETWEEN operator. |
yii\mongodb\Collection |
buildCondition() | Parses the condition specification and generates the corresponding Mongo condition. | yii\mongodb\Collection |
buildHashCondition() | Creates a condition based on column-value pairs. | yii\mongodb\Collection |
buildInCondition() | Creates an Mongo condition with the IN operator. |
yii\mongodb\Collection |
buildLikeCondition() | Creates a Mongo condition, which emulates the LIKE operator. |
yii\mongodb\Collection |
buildNotCondition() | Composes NOT condition. |
yii\mongodb\Collection |
buildOrCondition() | Connects two or more conditions with the OR operator. |
yii\mongodb\Collection |
buildRegexCondition() | Creates a Mongo regular expression condition. | yii\mongodb\Collection |
buildSimpleCondition() | Creates an Mongo condition like {$operator:{field:value}} . |
yii\mongodb\Collection |
createIndex() | Creates an index on the collection and the specified fields. | yii\mongodb\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\Collection |
dropAllIndexes() | Drops all indexes for this collection. | yii\mongodb\Collection |
dropIndex() | Drop indexes for specified column(s). | yii\mongodb\Collection |
find() | Returns a cursor for the search results. | yii\mongodb\Collection |
findAndModify() | Updates a document and returns it. | yii\mongodb\Collection |
findOne() | Returns a single document. | yii\mongodb\Collection |
fullTextSearch() | Performs full text search. | yii\mongodb\Collection |
get() | Retrieves the file with given _id. | yii\mongodb\file\Collection |
getChunkCollection() | Returns the Mongo collection for the file chunks. | yii\mongodb\file\Collection |
getFullName() | yii\mongodb\Collection | |
getLastError() | yii\mongodb\Collection | |
getName() | yii\mongodb\Collection | |
group() | Performs aggregation using Mongo "group" command. | yii\mongodb\Collection |
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 |
mapReduce() | Performs aggregation using Mongo "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 |
update() | Updates the rows, which matches given criteria by given data. | yii\mongodb\Collection |
Protected Methods
Method | Description | Defined By |
---|---|---|
composeLogToken() | Composes log/profile token. | yii\mongodb\Collection |
encodeLogData() | Encodes complex log data into JSON format string. | yii\mongodb\Collection |
ensureMongoId() | Converts given value into \yii\mongodb\MongoId instance. | yii\mongodb\Collection |
normalizeConditionKeyword() | Converts "\yii\db*" quick condition keyword into actual Mongo condition keyword. | yii\mongodb\Collection |
normalizeIndexKeys() | Compose index keys from given columns/keys list. | yii\mongodb\Collection |
processLogData() | Pre-processes the log data before sending it to json_encode() . |
yii\mongodb\Collection |
tryLastError() | Throws an exception if there was an error on the last operation. | yii\mongodb\Collection |
tryResultError() | Checks if command execution result ended with an error. | yii\mongodb\Collection |
Property Details
Method Details
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. |
Retrieves the file with given _id.
public \MongoGridFSFile|null get ( $id ) | ||
$id | mixed | _id of the file to find. |
return | \MongoGridFSFile|null | Found file, or null if file does not exist |
---|---|---|
throws | yii\mongodb\Exception | on failure. |
Returns the Mongo 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. |
---|
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. |
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. |
Creates new file in GridFS collection from uploaded file.
Additional attributes can be added file document using $metadata.
public mixed insertUploads ( $name, $metadata = [] ) | ||
$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. |
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. |
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. |