MongoDB\Driver\Manager::__construct

(mongodb >=1.0.0)

MongoDB\Driver\Manager::__constructCreate new MongoDB Manager

Описание

final public MongoDB\Driver\Manager::__construct ( string $uri [, array $options [, array $driverOptions ]] )

Constructs a new MongoDB\Driver\Manager object with the specified options.

Список параметров

uri

A » mongodb:// connection URI:

mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

The uri is a URL, hence any special characters in its components need to be URL encoded according to » RFC 3986. This is particularly relevant to the username and password, which can often include special characters such as @, :, or %. The rawurlencode() function may be used to encode constituent parts of the URI.

options

» Connection string options.

Замечание:

Specifying options via the options argument will overwrite any options with the same name in the uri argument.

driverOptions

Any driver-specific options not included in MongoDB connection string specification.

Ошибки

Примеры

Пример #1 MongoDB\Driver\Manager::__construct() basic examples

Connecting to standalone MongoDB node:

<?php

$manager 
= new MongoDB\Driver\Manager("mongodb://example.com:27017");

?>

Connecting to a replica set:

<?php

$manager 
= new MongoDB\Driver\Manager("mongodb://rs1.example.com,rs2.example.com/?replicaSet=myReplicaSet");

?>

Connecting to a sharded cluster (i.e. one or more mongos instances):

<?php

$manager 
= new MongoDB\Driver\Manager("mongodb://mongos1.example.com,mongos2.example.com/");

?>

Connecting to MongoDB with authentication credentials for a particular user and database:

<?php

$manager 
= new MongoDB\Driver\Manager("mongodb://myusername:mypassword@example.com:27017/mydatabase");

?>

Connecting to MongoDB with authentication credentials for a particular user and database, where the username or password includes special characters (e.g. @, :, %). In the following example, myp@ss:w%rd is being used as the password:

<?php

$manager 
= new MongoDB\Driver\Manager("mongodb://myusername:myp%40ss%3Aw%25rd@example.com:27017/mydatabase");

?>

Connecting to MongoDB with SSL and a client certificate:

<?php

$manager 
= new MongoDB\Driver\Manager(
    
"mongodb://username:password@example.com:28071/admin?ssl=true",
    [],
    [
        
"local_cert" => "/path/to/client.pem",
        
"passphrase" => "Very secretive client.pem passphrase",
    ]
);
?>

Смотрите также

Коментарии

Please note, if you send socketTimeoutMs value as 0 to disable timeout (according to MongoDB documentation), it will be considered as default value which is 300,000 ms in PHP driver. So send some really huge amount in case if you need to disable limitation.
2017-07-06 17:20:27
http://php5.kiev.ua/manual/ru/mongodb-driver-manager.construct.html
Please note, if you send socketTimeoutMs value as 0 to disable timeout (according to MongoDB documentation), it will be considered as default value which is 300,000 ms in PHP driver. So send some really huge amount in case if you need to disable limitation.
2017-07-06 17:31:37
http://php5.kiev.ua/manual/ru/mongodb-driver-manager.construct.html

    Поддержать сайт на родительском проекте КГБ