MongoDB\Driver\Manager::__construct
(mongodb >=1.0.0)
MongoDB\Driver\Manager::__construct — Create new MongoDB Manager
説明
$uri
= null
, ?array $uriOptions
= null
, ?array $driverOptions
= null
)Constructs a new MongoDB\Driver\Manager object with the specified options.
注意: Per the » Server Discovery and Monitoring Specification, this constructor performs no I/O. Connections will be initialized on demand, when the first operation is executed.
注意: When specifying any SSL or TLS URI options via the connection string or
uriOptions
parameter, the extension will implicitly enable TLS for its connections. To avoid this, either explicitly disable thetls
option or don't specify any TLS options.
注意: On Unix platforms, the extension is sensitive to scripts that use the fork() system call without also calling exec(). Users are advised not to re-use MongoDB\Driver\Manager instances in a forked child process.
パラメータ
uri
-
A » mongodb:// connection URI:
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[defaultAuthDb][?options]]
Defaults to
"mongodb://127.0.0.1:27017"
if unspecified.For details on supported URI options, see » Connection String Options in the MongoDB manual. » Connection pool options are not supported, as the extension does not implement connection pools.
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%
. When connecting via a Unix domain socket, the socket path may contain special characters such as slashes and must be encoded. The rawurlencode() function may be used to encode constituent parts of the URI.The
defaultAuthDb
component may be used to specify the database name associated with the user's credentials; however theauthSource
URI option will take priority if specified. If neitherdefaultAuthDb
norauthSource
are specified, theadmin
database will be used by default. ThedefaultAuthDb
component has no effect in the absence of user credentials. uriOptions
-
Additional » connection string options, which will overwrite any options with the same name in the
uri
parameter.uriOptions Option Type Description appname string MongoDB 3.4+ has the ability to annotate connections with metadata provided by the connecting client. This metadata is included in the server's logs upon establishing a connection and also recorded in slow query logs when database profiling is enabled.
This option may be used to specify an application name, which will be included in the metadata. The value cannot exceed 128 characters in length.
authMechanism string The authentication mechanism that MongoDB will use to authenticate the connection. For additional details and a list of supported values, see » Authentication Options in the MongoDB manual.
authMechanismProperties array Properties for the selected authentication mechanism. For additional details and a list of supported properties, see the » Driver Authentication Specification.
注意: When not specified in the URI string, this option is expressed as an array of key/value pairs. The keys and values in this array should be strings.
authSource string The database name associated with the user's credentials. Defaults to the database component of the connection URI, or the
admin
database if both are unspecified.For authentication mechanisms that delegate credential storage to other services (e.g. GSSAPI), this should be
"$external"
.canonicalizeHostname bool If
true
, the driver will resolve the real hostname for the server IP address before authenticating via SASL. Some underlying GSSAPI layers already do this, but the functionality may be disabled in their config (e.g.krb.conf
). Defaults tofalse
.This option is a deprecated alias for the
"CANONICALIZE_HOST_NAME"
property of the"authMechanismProperties"
URI option.compressors string A prioritized, comma-delimited list of compressors that the client wants to use. Messages are only compressed if the client and server share any compressors in common, and the compressor used in each direction will depend on the individual configuration of the server or driver. See the » Driver Compression Specification for more information.
connectTimeoutMS int The time in milliseconds to attempt a connection before timing out. Defaults to 10,000 milliseconds.
directConnection bool This option can be used to control replica set discovery behavior when only a single host is provided in the connection string. By default, providing a single member in the connection string will establish a direct connection or discover additional members depending on whether the
"replicaSet"
URI option is omitted or present, respectively. Specifyfalse
to force discovery to occur (if"replicaSet"
is omitted) or specifytrue
to force a direct connection (if"replicaSet"
is present).gssapiServiceName string Set the Kerberos service name when connecting to Kerberized MongoDB instances. This value must match the service name set on MongoDB instances (i.e. » saslServiceName server parameter). Defaults to
"mongodb"
.This option is a deprecated alias for the
"SERVICE_NAME"
property of the"authMechanismProperties"
URI option.heartbeatFrequencyMS int Specifies the interval in milliseconds between the driver's checks of the MongoDB topology, counted from the end of the previous check until the beginning of the next one. Defaults to 60,000 milliseconds.
Per the » Server Discovery and Monitoring Specification, this value cannot be less than 500 milliseconds.
journal bool Corresponds to the default write concern's
journal
parameter. Iftrue
, writes will require acknowledgement from MongoDB that the operation has been written to the journal. For details, see MongoDB\Driver\WriteConcern.loadBalanced bool Specifies whether the driver is connecting to a MongoDB cluster through a load balancer. If
true
, the driver may only connect to a single host (specified by either the connection string or SRV lookup), the"directConnection"
URI option cannot betrue
, and the"replicaSet"
URI option must be omitted. Defaults tofalse
.localThresholdMS int The size in milliseconds of the latency window for selecting among multiple suitable MongoDB instances while resolving a read preference. Defaults to 15 milliseconds.
maxStalenessSeconds int Corresponds to the read preference's
"maxStalenessSeconds"
. Specifies, in seconds, how stale a secondary can be before the client stops using it for read operations. By default, there is no maximum staleness and clients will not consider a secondary’s lag when choosing where to direct a read operation. For details, see MongoDB\Driver\ReadPreference.If specified, the max staleness must be a signed 32-bit integer greater than or equal to
MongoDB\Driver\ReadPreference::SMALLEST_MAX_STALENESS_SECONDS
(i.e. 90 seconds).password string The password for the user being authenticated. This option is useful if the password contains special characters, which would otherwise need to be URL encoded for the connection URI. readConcernLevel string Corresponds to the read concern's level
parameter. Specifies the level of read isolation. For details, see MongoDB\Driver\ReadConcern.readPreference string Corresponds to the read preference's
mode
parameter. Defaults to"primary"
. For details, see MongoDB\Driver\ReadPreference.readPreferenceTags array Corresponds to the read preference's
tagSets
parameter. Tag sets allow you to target read operations to specific members of a replica set. For details, see MongoDB\Driver\ReadPreference.注意: When not specified in the URI string, this option is expressed as an array consistent with the format expected by MongoDB\Driver\ReadPreference::__construct().
replicaSet string Specifies the name of the replica set.
retryReads bool Specifies whether or not the driver should automatically retry certain read operations that fail due to transient network errors or replica set elections. This functionality requires MongoDB 3.6+. Defaults to
true
.See the » Retryable Reads Specification for more information.
retryWrites bool Specifies whether or not the driver should automatically retry certain write operations that fail due to transient network errors or replica set elections. This functionality requires MongoDB 3.6+. Defaults to
true
.See » Retryable Writes in the MongoDB manual for more information.