|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mongodb.MongoURI
public class MongoURI
Represents a URI which can be used to create a Mongo 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=
for the default values for all options
Field Summary | |
---|---|
static String |
MONGODB_PREFIX
|
Constructor Summary | |
---|---|
MongoURI(String uri)
Creates a MongoURI described by a String. |
Method Summary | |
---|---|
Mongo |
connect()
creates a Mongo instance based on the URI |
DBCollection |
connectCollection(DB db)
returns the URI's Collection from a given DB object |
DBCollection |
connectCollection(Mongo m)
returns the URI's Collection from a given Mongo instance |
DB |
connectDB()
returns the DB object from a newly created Mongo instance based on this URI |
DB |
connectDB(Mongo m)
returns the URI's DB object from a given Mongo instance |
String |
getCollection()
Gets the collection name |
String |
getDatabase()
Gets the database name |
List<String> |
getHosts()
Gets the list of hosts |
MongoOptions |
getOptions()
Gets the options |
char[] |
getPassword()
Gets the password |
String |
getUsername()
Gets the username |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String MONGODB_PREFIX
Constructor Detail |
---|
public MongoURI(String uri)
uri
- the URI
Method Detail |
---|
public String getUsername()
public char[] getPassword()
public List<String> getHosts()
public String getDatabase()
public String getCollection()
public MongoOptions getOptions()
public Mongo connect() throws UnknownHostException
MongoException
UnknownHostException
public DB connectDB() throws UnknownHostException
MongoException
UnknownHostException
public DB connectDB(Mongo m)
m
-
public DBCollection connectCollection(DB db)
db
-
public DBCollection connectCollection(Mongo m)
m
-
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |