diff --git a/reference/mongo/mongo/construct.xml b/reference/mongo/mongo/construct.xml index 847868a711..5d1ea61396 100644 --- a/reference/mongo/mongo/construct.xml +++ b/reference/mongo/mongo/construct.xml @@ -16,12 +16,12 @@ If no parameters are passed, this connects to "localhost:27017" (or whatever - was specified in php.ini for - mongo.default_host and + was specified in php.ini for + mongo.default_host and mongo.default_port). - server should have the form: + server should have the form: - The connection string always starts with mongodb://, to - indicate it is a connection string in this form. + The connection string always starts with mongodb://, to + indicate it is a connection string in this form. If username and password - are specified, the constructor will attempt to authenticate the connection + are specified, the constructor will attempt to authenticate the connection with the database before returning. Username and password are optional - and must be followed by an @, if specified. + and must be followed by an @, if specified. - At least one host must be given (port optional, always defaulting to 27017) - and as many hosts as desired may be connected to. Host names are - comma-separated and the constructor will return successfully if it connected - to at least one host. If it could not connect to any of the hosts, it will + At least one host must be given (port optional, always defaulting to 27017) + and as many hosts as desired may be connected to. Host names are + comma-separated and the constructor will return successfully if it connected + to at least one host. If it could not connect to any of the hosts, it will throw a MongoConnectionException. Finally, if you specified a username and password, you may specify a database - to authenticate with. If db is not specified, "admin" + to authenticate with. If db is not specified, "admin" will be used. @@ -79,25 +79,10 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db "connect" - If the constructor should connect before returning. Default is + If the constructor should connect before returning. Default is &true;. - - - "persist" - - - If the connection should be persistent. If set, the connection will - be persistent. The string representation of the value is used as an - id for the connection, so two instances of - Mongo that are initialized with - array("persist" => "foobar") will share the same - database connection, whereas an instance initialized with - array("persist" => "barbaz") will use a different - database connection. - - "timeout" @@ -112,7 +97,7 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db "replicaSet" - If this hosts listed are seeds of a replica set. If they are, the + The name of the replica set to connect to. If this is given, the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed. See the replica set example below @@ -155,7 +140,7 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db &reftitle.errors; - Throws MongoConnectionException if it tries and fails + Throws MongoConnectionException if it tries and fails to connect to the database for all hostnames given. It will also throw a MongoConnnectionException if an invalid username or password is given. See MongoConnectionException @@ -176,6 +161,36 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db + 1.2.0 + + + Removed the persist option, as all connections are now persistent. It + can still be used, but it doesn't affect anything. + + + + "persist" + + + + If the connection should be persistent. If set, the connection will + be persistent. The string representation of the value is used as an + id for the connection, so two instances of + Mongo that are initialized with + array("persist" => "foobar") will share the same + database connection, whereas an instance initialized with + array("persist" => "barbaz") will use a different + database connection. + + + + + + + The "replicaSet" parameter now takes a string, not a boolean (although + boolean is still accepted). + + 1.0.2 Changed constructor to take an array of options. Pre-1.0.2, the @@ -197,7 +212,7 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db - Optional boolean parameter specifying if the constructor should + Optional boolean parameter specifying if the constructor should connect to the database before returning. Defaults to &true;. @@ -234,7 +249,7 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db 1.2.0 - Added the username and password + Added the username and password options. @@ -258,17 +273,17 @@ mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db true)); +$m1 = new Mongo("mongodb://sf2.example.com,ny1.example.com", array("replicaSet" => "myReplSet")); // you only need to pass a single seed, the driver will derive the full list and // find the master from this seed -$m2 = new Mongo("mongodb://ny1.example.com", array("replicaSet" => true)); +$m2 = new Mongo("mongodb://ny1.example.com", array("replicaSet" => "myReplSet")); ?> ]]> - If the current master fails, the driver will figure out which secondary + If the current master fails, the driver will figure out which secondary server became the new master and automatically start using that connection. Automatic failover will not work correctly if replicaSet is not specified. @@ -280,20 +295,20 @@ $m2 = new Mongo("mongodb://ny1.example.com", array("replicaSet" => true)); If you include seeds from two separate replica sets, behavior is undefined. - See the - core documentation on + See the + core documentation on replica sets for more information. Connecting to a domain socket - In version 1.0.9+, you can use a UNIX domain socket to connect to an + In version 1.0.9+, you can use a UNIX domain socket to connect to an instance of MongoDB running locally. This should be slightly faster than using a network connection. - In version 1.5.0, the MongoDB server automatically opens a socket at + In version 1.5.0, the MongoDB server automatically opens a socket at /tmp/mongodb-<port>.sock. You can connect to this by specifying the path in your connection string: @@ -317,43 +332,6 @@ $m = new Mongo("mongodb:///tmp/mongodb-20000.sock"); // try to connect to the domain socket, fall back to localhost connection $m = new MongoDB("mongodb:///tmp/mongodb-27017.sock,localhost:27017"); -?> -]]> - - - - <function>Mongo::__construct</function> persistent connection example - - A persistent connection will last for more than one request (usually... - milage may vary depending on server). It can save significant time to - reuse connections, as creating a connection is a time-intensive process. - - - A persistent connection is identified by the server string and an id - string. - - - "")); - -// uses the same connection as $m1 -$m2 = new Mongo("mongodb://localhost", array("persist" => "")); - -// creates a new connection -$m3 = new Mongo("mongodb://127.0.0.1", array("persist" => "")); - -// creates a new connection -$m4 = new Mongo("mongodb://127.0.0.1:27017", array("persist" => "")); - -// creates a new connection -$m5 = new Mongo("mongodb://localhost", array("persist" => "foo")); - -// uses the $m5 connection -$m6 = new Mongo("mongodb://localhost", array("persist" => "foo")); - ?> ]]> @@ -361,7 +339,7 @@ $m6 = new Mongo("mongodb://localhost", array("persist" => "foo")); <function>Mongo::__construct</function> authentication example - A user must exist in the admin database before attempting to use + A user must exist in the admin database before attempting to use authentication. You can create one with the Mongo shell by running: @@ -412,4 +390,4 @@ End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 ---> +-->