lithium\data\source\MongoDb::__construct()
Overrides
lithium\data\Source::__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. Use the array format for multiple hosts:['167.221.1.5:11222', '167.221.1.6']
'login'
string: Username to use when connecting to server. Defaults to'root'
.'password'
string: Password to use when connecting to server. Defaults to''
.'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.
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 = []) {
$defaults = [
'host' => static::DEFAULT_HOST . ':' . static::DEFAULT_PORT,
'login' => null,
'password' => null,
'database' => null,
'dsn' => null,
'timeout' => 1000,
'uriOptions' => [
'w' => 'majority',
'wTimeoutMS' => 10000,
'journal' => true,
'readConcernLevel' => 'local',
'readPreference' => 'primary',
'readPreferenceTags' => [],
],
'driverOptions' => [
'tlsAllowInvalidHostnames' => false,
'tlsAllowInvalidCertificates' => false
]
];
$config = Set::merge($defaults, $config);
if (!isset($config['uriOptions']['connectTimeoutMS']) && $config['timeout']) {
$config['uriOptions']['connectTimeoutMS'] = $config['timeout'];
}
parent::__construct($config);
}