public class ConnectionString
extends java.lang.Object
Represents a Connection String. The Connection String describes the hosts to be used and options.
The format of the Connection String is:
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
mongodb:// is a required prefix to identify that this is a string in the standard connection format.username:password@ are optional. If given, the driver will attempt to login to a database after
connecting to a database server. For some authentication mechanisms, only the username is specified and the password is not,
in which case the ":" after the username is left off as wellhost1 is the only required part of the connection string. It identifies a server address to connect to.:portX is optional and defaults to :27017 if not provided./database is the name of the database to login to and thus is only relevant if the
username:password@ syntax is used. If not specified the "admin" database will be used by default.?options are connection options. Note that if database is absent there is still a /
required between the last host and the ? introducing the options. Options are name=value pairs and the pairs
are separated by "&". For backwards compatibility, ";" is accepted as a separator in addition to "&",
but should be considered as deprecated.The following options are supported (case insensitive):
Server Selection Configuration:
serverSelectionTimeoutMS=ms: How long the driver will wait for server selection to succeed before throwing an exception.localThresholdMS=ms: When choosing among multiple MongoDB servers to send a request, the driver will only
send that request to a server whose ping time is less than or equal to the server with the fastest ping time plus the local
threshold.Server Monitoring Configuration:
heartbeatFrequencyMS=ms: The frequency that the driver will attempt to determine the current state of each server in the
cluster.Replica set configuration:
replicaSet=name: Implies that the hosts given are a seed list, and the driver will attempt to find
all members of the set.Connection Configuration:
Connection Configuration:
streamType=nio2|netty: The stream type to use for connections. If unspecified, nio2 will be used.ssl=true|false: Whether to connect using SSL.sslInvalidHostNameAllowed=true|false: Whether to allow invalid host names for SSL connections.connectTimeoutMS=ms: How long a connection can take to be opened before timing out.socketTimeoutMS=ms: How long a send or receive on a socket can take before timing out.maxIdleTimeMS=ms: Maximum idle time of a pooled connection. A connection that exceeds this limit will be closedmaxLifeTimeMS=ms: Maximum life time of a pooled connection. A connection that exceeds this limit will be closedConnection pool configuration:
maxPoolSize=n: The maximum number of connections in the connection pool.waitQueueMultiple=n : this multiplier, multiplied with the maxPoolSize setting, gives the maximum number of
threads that may be waiting for a connection to become available from the pool. All further threads will get an
exception right away.waitQueueTimeoutMS=ms: The maximum wait time in milliseconds that a thread may wait for a connection to
become available.Write concern configuration:
safe=true|false
true: the driver sends a getLastError command after every update to ensure that the update succeeded
(see also w and wtimeoutMS).false: the driver does not send a getLastError command after every update.journal=true|false
true: the driver waits for the server to group commit to the journal file on disk.false: the driver does not wait for the server to group commit to the journal file on disk.w=wValue
safe=true."majority"wtimeoutMS=ms
safe=true.wRead preference configuration:
readPreference=enum: The read preference for this connection.
primaryprimaryPreferredsecondarysecondaryPreferrednearestreadPreferenceTags=string. A representation of a tag set as a comma-separated list of colon-separated
key-value pairs, e.g. "dc:ny,rack:1". Spaces are stripped from beginning and end of all keys and values.
To specify a list of tag sets, using multiple readPreferenceTags,
e.g. readPreferenceTags=dc:ny,rack:1;readPreferenceTags=dc:ny;readPreferenceTags=
Authentication configuration:
authMechanism=MONGO-CR|GSSAPI|PLAIN|MONGODB-X509: The authentication mechanism to use if a credential was supplied.
The default is unspecified, in which case the client will pick the most secure mechanism available based on the sever version. For the
GSSAPI and MONGODB-X509 mechanisms, no password is accepted, only the username.
authSource=string: The source of the authentication credentials. This is typically the database that
the credentials have been created. The value defaults to the database specified in the path portion of the connection string.
If the database is specified in neither place, the default value is "admin". This option is only respected when using the MONGO-CR
mechanism (the default).
authMechanismProperties=PROPERTY_NAME:PROPERTY_VALUE,PROPERTY_NAME2:PROPERTY_VALUE2: This option allows authentication
mechanism properties to be set on the connection string.
gssapiServiceName=string: This option only applies to the GSSAPI mechanism and is used to alter the service name.
Deprecated, please use authMechanismProperties=SERVICE_NAME:string instead.
| 构造器和说明 |
|---|
ConnectionString(java.lang.String connectionString)
Creates a ConnectionString from the given string.
|
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
equals(java.lang.Object o) |
java.lang.String |
getCollection()
Gets the collection name
|
java.lang.String |
getConnectionString()
Get the unparsed connection string.
|
java.lang.Integer |
getConnectTimeout()
Gets the socket connect timeout specified in the connection string.
|
java.util.List<MongoCredential> |
getCredentialList()
Gets the credentials.
|
java.lang.String |
getDatabase()
Gets the database name
|
java.lang.Integer |
getHeartbeatFrequency() |
java.util.List<java.lang.String> |
getHosts()
Gets the list of hosts
|
java.lang.Integer |
getLocalThreshold() |
java.lang.Integer |
getMaxConnectionIdleTime()
Gets the maximum connection idle time specified in the connection string.
|
java.lang.Integer |
getMaxConnectionLifeTime()
Gets the maximum connection life time specified in the connection string.
|
java.lang.Integer |
getMaxConnectionPoolSize()
Gets the maximum connection pool size specified in the connection string.
|
java.lang.Integer |
getMaxWaitTime()
Gets the maximum wait time of a thread waiting for a connection specified in the connection string.
|
java.lang.Integer |
getMinConnectionPoolSize()
Gets the minimum connection pool size specified in the connection string.
|
char[] |
getPassword()
Gets the password
|
ReadConcern |
getReadConcern()
Gets the read concern specified in the connection string.
|
ReadPreference |
getReadPreference()
Gets the read preference specified in the connection string.
|
java.lang.String |
getRequiredReplicaSetName()
Gets the required replica set name specified in the connection string.
|
java.lang.Integer |
getServerSelectionTimeout() |
java.lang.Integer |
getSocketTimeout()
Gets the socket timeout specified in the connection string.
|
java.lang.Boolean |
getSslEnabled()
Gets the SSL enabled value specified in the connection string.
|
java.lang.Boolean |
getSslInvalidHostnameAllowed()
Gets the SSL invalidHostnameAllowed value specified in the connection string.
|
java.lang.String |
getStreamType()
Gets the stream type value specified in the connection string.
|
java.lang.Integer |
getThreadsAllowedToBlockForConnectionMultiplier()
Gets the multiplier for the number of threads allowed to block waiting for a connection specified in the connection string.
|
java.lang.String |
getURI()
已过时。
|
java.lang.String |
getUsername()
Gets the username
|
WriteConcern |
getWriteConcern()
Gets the write concern specified in the connection string.
|
int |
hashCode() |
java.lang.String |
toString() |
public ConnectionString(java.lang.String connectionString)
connectionString - the connection stringpublic java.lang.String getUsername()
public char[] getPassword()
public java.util.List<java.lang.String> getHosts()
public java.lang.String getDatabase()
public java.lang.String getCollection()
@Deprecated public java.lang.String getURI()
getConnectionString()public java.lang.String getConnectionString()
public java.util.List<MongoCredential> getCredentialList()
public ReadPreference getReadPreference()
public ReadConcern getReadConcern()
public WriteConcern getWriteConcern()
public java.lang.Integer getMinConnectionPoolSize()
public java.lang.Integer getMaxConnectionPoolSize()
public java.lang.Integer getThreadsAllowedToBlockForConnectionMultiplier()
public java.lang.Integer getMaxWaitTime()
public java.lang.Integer getMaxConnectionIdleTime()
public java.lang.Integer getMaxConnectionLifeTime()
public java.lang.Integer getConnectTimeout()
public java.lang.Integer getSocketTimeout()
public java.lang.Boolean getSslEnabled()
public java.lang.String getStreamType()
public java.lang.Boolean getSslInvalidHostnameAllowed()
public java.lang.String getRequiredReplicaSetName()
public java.lang.Integer getServerSelectionTimeout()
public java.lang.Integer getLocalThreshold()
public java.lang.Integer getHeartbeatFrequency()
public java.lang.String toString()
toString 在类中 java.lang.Objectpublic boolean equals(java.lang.Object o)
equals 在类中 java.lang.Objectpublic int hashCode()
hashCode 在类中 java.lang.Object