An array of options for the connection. Currently available options
include:
-
"authMechanism"
Available mechanisms are:
-
"authSource"
Should be set to the database name where the user is defined it.
-
"connect"
If the constructor should connect before returning. Default is
true
. When set to false
the driver will
automatically connect to the server whenever
it is necessary to do a query. Alternatively, you can run
MongoClient::connect() manually.
Avertizare
This option is not supported through the connection string.
-
"connectTimeoutMS"
How long a connection can take to be opened before timing out in
milliseconds. Defaults to 60000
(60 seconds).
If -1
is specified, no connection timeout will be
applied and PHP will use
default_socket_timeout.
-
"db"
The database to authenticate against can be specified here, instead of
including it in the host list. This overrides a database given in the
host list.
-
"fsync"
When "fsync"
is set, all write operations will
block until the database has flushed the changes to disk. This makes
the write operations slower, but it guarantees that writes have
succeeded and that the operations can be recovered in case of total
system failure.
If the MongoDB server has journaling enabled, this option is identical
to "journal". If journaling is not enabled, this
option ensures that write operations will be synced to database files
on disk.
Notă:
If journaling is enabled, users are strongly encouraged to use the
"journal"
option instead of
"fsync"
. Do not use "fsync"
and
"journal"
simultaneously, as that will result in
an error.
-
"journal"
When "journal"
is set, all write operations will
block until the database has flushed the changes to the journal on
disk. This makes the write operations slower, but it guarantees that
writes have succeeded and that the operations can be recovered in case
of total system failure.
Notă:
If this option is used and journaling is disabled, MongoDB 2.6+ will
raise an error and the write will fail; older server versions will
simply ignore the option.
-
"gssapiServiceName"
Sets the » Kerberos service principal. Only applicable when authMechanism=GSSAPI. Defaults to "mongodb".
-
"password"
The password can be specified here, instead of including it in the
host list. This is especially useful if a password has a "@" in it.
This overrides a password set in the host list.
-
"readPreference"
Specifies the read preference type. Read preferences provide you
with control from which secondaries data can be read from.
Allowed values are: MongoClient::RP_PRIMARY
,
MongoClient::RP_PRIMARY_PREFERRED
,
MongoClient::RP_SECONDARY
,
MongoClient::RP_SECONDARY_PREFERRED
and
MongoClient::RP_NEAREST
.
See the documentation on read
preferences for more information.
-
"readPreferenceTags"
Specifies the read preference tags as an array of strings. Tags can be
used in combination with the readPreference
option
to further control which secondaries data might be read from.
See the documentation on read
preferences for more information.
-
"replicaSet"
The name of the replica set to connect to. If this is given, the
primary will be automatically be determined. This means that the
driver may end up connecting to a server that was not even listed.
See the replica set example below for details.
-
"secondaryAcceptableLatencyMS"
When reading from a secondary (using ReadPreferences), do not read from secondaries known to be more then
secondaryAcceptableLatencyMS
away from us. Defaults to 15
-
"socketTimeoutMS"
How long a socket operation (read or write) can take before timing out
in milliseconds. Defaults to 30000
(30 seconds).
If -1
is specified, socket operations may block
indefinitely. This option may also be set on a per-operation basis
using MongoCursor::timeout() for queries or the
"socketTimeoutMS"
option for write methods.
Notă:
This is a client-side timeout. If a write operation times out, there
is no way to know if the server actually handled the write or not, as
a MongoCursorTimeoutException will be thrown
in lieu of returning a write result.
-
"ssl"
A boolean to specify whether you want to enable SSL for the
connections to MongoDB. Extra options such as certificates
can be set with SSL context options.
-
"username"
The username can be specified here, instead of including it in the
host list. This is especially useful if a username has a ":" in it.
This overrides a username set in the host list.
-
"w"
The w
option specifies the
Write Concern for the driver,
which determines how long the driver blocks when writing. The
default value is 1
.
This option is applicable when connecting to both single servers and
replica sets. A positive value controls how many
nodes must acknowledge the write instruction before the driver
continues. A value of 1
would require the single
server or primary (in a replica set) to acknowledge the write
operation. A value of 3
would cause the driver to
block until the write has been applied to the primary as well as two
secondary servers (in a replica set).
A string value is used to control which tag sets are taken into
account for write concerns. "majority"
is special
and ensures that the write operation has been applied to the majority
(more than 50%) of the participating nodes.
-
"wTimeoutMS"
This option specifies the time limit, in milliseconds, for
write concern
acknowledgement. It is only applicable for write operations where
"w"
is greater than 1
, as the
timeout pertains to replication. If the write concern is not satisfied
within the time limit, a MongoCursorException
will be thrown. A value of 0
may be specified to
block indefinitely. The default value is 10000
(ten seconds).
The following options are deprecated and should no longer be used: