lithium\data\source\MongoDb::__construct()
Overrides
lithium\core\Object::__construct()
Constructor.
Parameters
-
array
$config
Configuration options required to connect to the database, including:
'database'
string: The name of the database to connect to. Defaults tonull
.'host'
string: The IP or machine name where Mongo is running, followed by a colon, and the port number. Defaults to'localhost:27017'
.'persistent'
mixed: Determines a persistent connection to attach to. See the$options
parameter ofMongo::__construct()
for more information. Defaults tofalse
, meaning no persistent connection is made.'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: array(Mongo::RP_SECONDARY_PREFERRED, array('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.
Returns
voidLinks
Source
public function __construct(array $config = array()) {
$host = 'localhost:27017';
$server = $this->_classes['server'];
if (class_exists($server, false)) {
$host = $server::DEFAULT_HOST . ':' . $server::DEFAULT_PORT;
}
$defaults = compact('host') + array(
'persistent' => false,
'login' => null,
'password' => null,
'database' => null,
'timeout' => 100,
'replicaSet' => false,
'schema' => null,
'gridPrefix' => 'fs',
'w' => 1,
'wTimeoutMS' => 10000,
'readPreference' => null,
'autoConnect' => false
);
parent::__construct($config + $defaults);
}