lithium\data\source\MongoDb::__construct()
Constructor.
Parameters
-
array
$config
Configuration options required to connect to the database, including:
'host'
string|array: A string in the form of'<host>'
,'<host>:<port>'
or':<port>'
indicating the host and/or port to connect to. When one or both are not provided uses general server defaults (if possible retrieved from the client implementation). Use the array format for multiple hosts:array('167.221.1.5:11222', '167.221.1.6')
'database'
string: The name of the database to connect to. Defaults tonull
.'timeout'
integer: The number of milliseconds a connection attempt will wait before timing out and throwing an exception. Defaults to100
.'schema'
\Closure: A closure or anonymous function which returns the schema information for a model class. See the$_schema
property for more information.'gridPrefix'
string: The default prefix for MongoDB'schunks
andfiles
collections. Defaults to'fs'
.'replicaSet'
string: See the documentation forMongo::__construct()
. Defaults tofalse
.'readPreference'
mixed: May either be a single value such as Mongo::RP_NEAREST, or an array containing a read preference and a tag set such as: (Mongo::RP_SECONDARY_PREFERRED, ['dc' => 'east] See the documentation forMongo::setReadPreference()
. Defaults to null. Typically, these parameters are set inConnections::add()
, when adding the adapter to the list of active connections.
Disables auto-connect, which is by default enabled in
Source
. Instead before each query execution the connection is checked and if needed (re-)established.
Returns
voidLinks
Source
public function __construct(array $config = []) {
if (class_exists($server = $this->_classes['server'], false)) {
$defaultHost = $server::DEFAULT_HOST . ':' . $server::DEFAULT_PORT;
} else {
$defaultHost = static::DEFAULT_HOST . ':' . static::DEFAULT_PORT;
}
$defaults = [
'host' => $defaultHost,
'login' => null,
'password' => null,
'database' => null,
'timeout' => 100,
'replicaSet' => false,
'schema' => null,
'gridPrefix' => 'fs',
'w' => 1,
'wTimeoutMS' => 10000,
'readPreference' => null,
'autoConnect' => false,
'dsn' => null
];
parent::__construct($config + $defaults);
}