public class MongoClientURI extends Object
The format of the URI is:
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.
host1is the only required part of the URI. It identifies a server address to connect to.
:portXis optional and defaults to :27017 if not provided.
/databaseis 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.
?optionsare connection options. Note that if
databaseis 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 Java driver supports the following options (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.
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.
Connection 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:
true: the driver sends a getLastError command after every update to ensure that the update succeeded (see also
false: the driver does not send a getLastError command after every update.
Read 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.
readPreferenceTags=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.
authMechanism=MONGO-CR|GSSAPI: The authentication mechanism to use if a credential was supplied. The default is MONGODB-CR, which is the native MongoDB Challenge Response mechanism.
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.
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
for the default values for all options
|Constructor and Description|
Creates a MongoURI from the given string.
Creates a MongoURI from the given URI string, and MongoClientOptions.Builder.
|Modifier and Type||Method and Description|
Gets the collection name
Gets the credentials.
Gets the database name
Gets the list of hosts
Gets the options
Gets the password
Get the unparsed URI.
Gets the username
public MongoClientURI(String uri)
uri- the URI
public MongoClientURI(String uri, MongoClientOptions.Builder builder)
uri- the URI
builder- a Builder
public String getUsername()
public char getPassword()
public String getDatabase()
public String getCollection()
public String getURI()
public MongoCredential getCredentials()
public MongoClientOptions getOptions()