Class yii\mongodb\Database
Inheritance | yii\mongodb\Database » yii\base\Object |
---|---|
Available since version | 2.0 |
Database represents the Mongo database information.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$mongoDb | \MongoDB | Mongo database instance. | yii\mongodb\Database |
Public Methods
Method | Description | Defined By |
---|---|---|
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 |
Protected Methods
Method | Description | Defined 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
Method Details
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.
public \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. |
Executes Mongo command.
public 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. |
Returns the Mongo collection with the given name.
public 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. |
---|
Returns Mongo GridFS collection with given prefix.
public 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. |
---|
public string getName ( ) | ||
return | string | Name of this database. |
---|
Selects collection with given name.
protected yii\mongodb\Collection selectCollection ( $name ) | ||
$name | string | Collection name. |
return | yii\mongodb\Collection | Collection instance. |
---|
Selects GridFS collection with given prefix.
protected yii\mongodb\file\Collection selectFileCollection ( $prefix ) | ||
$prefix | string | File collection prefix. |
return | yii\mongodb\file\Collection | File collection instance. |
---|
Checks if command execution result ended with an error.
protected void tryResultError ( $result ) | ||
$result | mixed | Raw command execution result. |
throws | yii\mongodb\Exception | if an error occurred. |
---|