Class yii\mongodb\Database

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

Database represents the Mongo database information.

Public Properties

Hide inherited properties

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

Public Methods

Hide inherited methods

MethodDescriptionDefined 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
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
createCollection() Creates new collection. yii\mongodb\Database
executeCommand() Executes Mongo command. yii\mongodb\Database
getCollection() Returns the Mongo collection with the given name. yii\mongodb\Database
getFileCollection() Returns Mongo GridFS collection with given prefix. yii\mongodb\Database
getName() yii\mongodb\Database
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

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
selectCollection() Selects collection with given name. yii\mongodb\Database
selectFileCollection() Selects GridFS collection with given prefix. yii\mongodb\Database
tryResultError() Checks if command execution result ended with an error. yii\mongodb\Database

Property Details

$fileCollection public read-only property
yii\mongodb\file\Collection getFileCollection$prefix 'fs'$refresh false )

Mongo GridFS collection.

$mongoDb public property
\MongoDB $mongoDb null

Mongo database instance.

$name public read-only property

Name of this database.

Method Details

createCollection() public method

Creates new collection.

Note: Mongo creates new collections automatically on the first demand, this method makes sense only for the migration script or for the case you need to create collection with the specific options.

\MongoCollection createCollection$name$options = [] )
$name string

Name of the collection

$options array

Collection options in format: "name" => "value"

return \MongoCollection

New Mongo collection instance.

throws yii\mongodb\Exception

on failure.

executeCommand() public method

Executes Mongo command.

array executeCommand$command$options = [] )
$command array

Command specification.

$options array

Options in format: "name" => "value"

return array

Database response.

throws yii\mongodb\Exception

on failure.

getCollection() public method

Returns the Mongo collection with the given name.

yii\mongodb\Collection getCollection$name$refresh false )
$name string

Collection name

$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 Mongo GridFS collection with given prefix.

yii\mongodb\file\Collection getFileCollection$prefix 'fs'$refresh false )
$prefix string

Collection prefix.

$refresh boolean

Whether to reload the collection instance even if it is found in the cache.

return yii\mongodb\file\Collection

Mongo GridFS collection.

getName() public method

string getName( )
return string

Name of this database.

selectCollection() protected method

Selects collection with given name.

yii\mongodb\Collection selectCollection$name )
$name string

Collection name.

return yii\mongodb\Collection

Collection instance.

selectFileCollection() protected method

Selects GridFS collection with given prefix.

yii\mongodb\file\Collection selectFileCollection$prefix )
$prefix string

File collection prefix.

return yii\mongodb\file\Collection

File collection instance.

tryResultError() protected method

Checks if command execution result ended with an error.

void tryResultError$result )
$result mixed

Raw command execution result.

throws yii\mongodb\Exception

if an error occurred.