public class MongoClientURI
extends java.lang.Object
The format of the URI is:
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database[.collection]][?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 well.host1 is the only required part of the URI. 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):
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:
ssl=true|false: Whether to connect using SSL.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.minPoolSize=n: The minimum 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.w=wValue
safe=true."majority"wtimeoutMS=ms
safe=true.wRead preference configuration:
slaveOk=true|false: Whether a driver connected to a replica set will send reads to slaves/secondaries.readPreference=enum: The read preference for this connection. If set, it overrides any slaveOk value.
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 URI.
If the database is specified in neither place, the default value is "admin". For GSSAPI, it's not necessary to specify
a source.
gssapiServiceName=string: This option only applies to the GSSAPI mechanism and is used to alter the service name..
Note: This class is a replacement for MongoURI, to be used with MongoClient. The main difference in
behavior is that the default write concern is WriteConcern.ACKNOWLEDGED.
for the default values for all options| Modifier and Type | Field and Description |
|---|---|
(package private) static java.util.Set<java.lang.String> |
allKeys |
(package private) static java.util.Set<java.lang.String> |
authKeys |
private java.lang.String |
collection |
private MongoCredential |
credentials |
private java.lang.String |
database |
(package private) static java.util.Set<java.lang.String> |
generalOptionsKeys |
private java.util.List<java.lang.String> |
hosts |
(package private) static java.util.logging.Logger |
LOGGER |
private MongoClientOptions |
options |
private static java.lang.String |
PREFIX |
(package private) static java.util.Set<java.lang.String> |
readPreferenceKeys |
private java.lang.String |
uri |
private static java.lang.String |
UTF_8 |
(package private) static java.util.Set<java.lang.String> |
writeConcernKeys |
| Constructor and Description |
|---|
MongoClientURI(java.lang.String uri)
Creates a MongoURI from the given string.
|
MongoClientURI(java.lang.String uri,
MongoClientOptions.Builder builder)
Creates a MongoURI from the given URI string, and MongoClientOptions.Builder.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) boolean |
_parseBoolean(java.lang.String _in) |
private ReadPreference |
buildReadPreference(java.lang.String readPreferenceType,
DBObject firstTagSet,
java.util.List<DBObject> remainingTagSets,
java.lang.Boolean slaveOk) |
private WriteConcern |
buildWriteConcern(java.lang.Boolean safe,
java.lang.String w,
int wTimeout,
boolean fsync,
boolean journal) |
private MongoCredential |
createCredentials(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap,
java.lang.String userName,
char[] password,
java.lang.String database) |
private MongoClientOptions |
createOptions(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap,
MongoClientOptions.Builder builder) |
private ReadPreference |
createReadPreference(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap) |
private WriteConcern |
createWriteConcern(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap) |
boolean |
equals(java.lang.Object o) |
java.lang.String |
getCollection()
Gets the collection name
|
MongoCredential |
getCredentials()
Gets the credentials.
|
java.lang.String |
getDatabase()
Gets the database name
|
java.util.List<java.lang.String> |
getHosts()
Gets the list of hosts
|
private java.lang.String |
getLastValue(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap,
java.lang.String key) |
MongoClientOptions |
getOptions()
Gets the options
|
char[] |
getPassword()
Gets the password
|
private DBObject |
getTagSet(java.lang.String tagSetString) |
java.lang.String |
getURI()
Get the unparsed URI.
|
java.lang.String |
getUsername()
Gets the username
|
int |
hashCode() |
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
parseOptions(java.lang.String optionsPart) |
java.lang.String |
toString() |
private void |
warnOnUnsupportedOptions(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap) |
private static final java.lang.String PREFIX
private static final java.lang.String UTF_8
static java.util.Set<java.lang.String> generalOptionsKeys
static java.util.Set<java.lang.String> authKeys
static java.util.Set<java.lang.String> readPreferenceKeys
static java.util.Set<java.lang.String> writeConcernKeys
static java.util.Set<java.lang.String> allKeys
private final MongoClientOptions options
private final MongoCredential credentials
private final java.util.List<java.lang.String> hosts
private final java.lang.String database
private final java.lang.String collection
private final java.lang.String uri
static final java.util.logging.Logger LOGGER
public MongoClientURI(java.lang.String uri)
uri - the URIpublic MongoClientURI(java.lang.String uri,
MongoClientOptions.Builder builder)
uri - the URIbuilder - a BuildergetOptions()private void warnOnUnsupportedOptions(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap)
private MongoClientOptions createOptions(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap, MongoClientOptions.Builder builder)
private WriteConcern createWriteConcern(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap)
private ReadPreference createReadPreference(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap)
private MongoCredential createCredentials(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap, java.lang.String userName, char[] password, java.lang.String database)
private java.lang.String getLastValue(java.util.Map<java.lang.String,java.util.List<java.lang.String>> optionsMap,
java.lang.String key)
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> parseOptions(java.lang.String optionsPart)
private ReadPreference buildReadPreference(java.lang.String readPreferenceType, DBObject firstTagSet, java.util.List<DBObject> remainingTagSets, java.lang.Boolean slaveOk)
private WriteConcern buildWriteConcern(java.lang.Boolean safe, java.lang.String w, int wTimeout, boolean fsync, boolean journal)
private DBObject getTagSet(java.lang.String tagSetString)
boolean _parseBoolean(java.lang.String _in)
public 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()
public java.lang.String getURI()
public MongoCredential getCredentials()
public MongoClientOptions getOptions()
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object