PHP Class yii\mongodb\Database

Since: 2.0
Author: Paul Klimov ([email protected])
Inheritance: extends yii\base\Object
Mostra file Open project: yiisoft/yii2-mongodb

Public Properties

Property Type Description
$connection MongoDB connection.
$name name of this database.

Public Methods

Method Description
clearCollections ( ) Clears internal collection lists.
createCollection ( string $name, array $options = [] ) : boolean Creates new collection.
createCommand ( array $document = [] ) : Command Creates MongoDB command associated with this database.
dropCollection ( string $name ) : boolean Drops specified collection.
getCollection ( string $name, boolean $refresh = false ) : Collection Returns the Mongo collection with the given name.
getFileCollection ( string $prefix = 'fs', boolean $refresh = false ) : Collection Returns Mongo GridFS collection with given prefix.
listCollections ( array $condition = [], array $options = [] ) : array Returns the list of available collections in this database.

Protected Methods

Method Description
selectCollection ( string $name ) : Collection Selects collection with given name.
selectFileCollection ( string $prefix ) : Collection Selects GridFS collection with given prefix.

Method Details

clearCollections() public method

This method can be used to break cycle references between Database and Collection instances.
public clearCollections ( )

createCollection() public method

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 createCollection ( string $name, array $options = [] ) : boolean
$name string name of the collection
$options array collection options in format: "name" => "value"
return boolean whether operation was successful.

createCommand() public method

Creates MongoDB command associated with this database.
Since: 2.1
public createCommand ( array $document = [] ) : Command
$document array command document contents.
return Command command instance.

dropCollection() public method

Drops specified collection.
Since: 2.1
public dropCollection ( string $name ) : boolean
$name string name of the collection
return boolean whether operation was successful.

getCollection() public method

Returns the Mongo collection with the given name.
public getCollection ( string $name, boolean $refresh = false ) : Collection
$name string collection name
$refresh boolean whether to reload the collection instance even if it is found in the cache.
return Collection Mongo collection instance.

getFileCollection() public method

Returns Mongo GridFS collection with given prefix.
public getFileCollection ( string $prefix = 'fs', boolean $refresh = false ) : Collection
$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.

listCollections() public method

Returns the list of available collections in this database.
Since: 2.1.1
public listCollections ( array $condition = [], array $options = [] ) : array
$condition array filter condition.
$options array options list.
return array collections information.

selectCollection() protected method

Selects collection with given name.
protected selectCollection ( string $name ) : Collection
$name string collection name.
return Collection collection instance.

selectFileCollection() protected method

Selects GridFS collection with given prefix.
protected selectFileCollection ( string $prefix ) : Collection
$prefix string file collection prefix.
return yii\mongodb\file\Collection file collection instance.

Property Details

$connection public_oe property

MongoDB connection.
public $connection

$name public_oe property

name of this database.
public $name