|
||||||||||
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.
This class has been superseded by <MongoClientURI
, and may be deprecated in a future release.
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=
MongoClientURI
,
for the default values for all options
Field Summary | |
---|---|
static String |
MONGODB_PREFIX
The prefix for mongodb URIs. |
Constructor Summary | |
---|---|
MongoURI(MongoClientURI mongoClientURI)
|
|
MongoURI(String uri)
Creates a MongoURI from 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 mongo)
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 mongo)
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
public MongoURI(MongoClientURI mongoClientURI)
Method Detail |
---|
public String getUsername()
public char[] getPassword()
public List<String> getHosts()
public String getDatabase()
public String getCollection()
public MongoOptions getOptions()
MongoOptions
for every call, so it's
possible to mutate the returned instance to change the defaults.
public Mongo connect() throws UnknownHostException
MongoException
UnknownHostException
public DB connectDB() throws UnknownHostException
MongoException
UnknownHostException
public DB connectDB(Mongo mongo)
mongo
- the Mongo instance to get the database from.
public DBCollection connectCollection(DB db)
db
- the database to get the collection from
public DBCollection connectCollection(Mongo mongo)
mongo
- the mongo instance to get the collection from
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |