|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mongodb.MongoClientURI
public class MongoClientURI
Represents a URI which can be used to create a MongoClient instance. The URI describes the hosts to be used and options.
The format of the URI 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.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 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.Connection Configuration:
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:
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
.w
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.
primary
primaryPreferred
secondary
secondaryPreferred
nearest
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. readPreferenceTags=dc:ny,rack:1;readPreferenceTags=dc:ny;readPreferenceTags=
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
Constructor Summary | |
---|---|
MongoClientURI(String uri)
Creates a MongoURI from the given string. |
Method Summary | |
---|---|
String |
getCollection()
Gets the collection name |
String |
getDatabase()
Gets the database name |
List<String> |
getHosts()
Gets the list of hosts |
MongoClientOptions |
getOptions()
Gets the options |
char[] |
getPassword()
Gets the password |
String |
getURI()
Get the unparsed URI. |
String |
getUsername()
Gets the username |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public MongoClientURI(String uri)
uri
- the URI
Method Detail |
---|
public String getUsername()
public char[] getPassword()
public List<String> getHosts()
public String getDatabase()
public String getCollection()
public String getURI()
public MongoClientOptions getOptions()
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |