com.mongodb
Class MongoURI

java.lang.Object
  extended by com.mongodb.MongoURI

public class MongoURI
extends Object

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]]
 

The Java driver supports the following options (case insensitive):

Replica set configuration:

Connection Configuration:

Connection pool configuration:

Write concern configuration:

Read preference configuration:

See Also:
MongoClientURI, for the default values for all options

Field Summary
static String MONGODB_PREFIX
          The prefix for mongodb URIs.
 
Constructor Summary
MongoURI(MongoClientURI mongoClientURI)
          Deprecated. 
MongoURI(String uri)
          Deprecated. Replaced by MongoClientURI.MongoClientURI(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
 MongoCredential getCredentials()
          Gets the credentials
 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

MONGODB_PREFIX

public static final String MONGODB_PREFIX
The prefix for mongodb URIs.

See Also:
Constant Field Values
Constructor Detail

MongoURI

@Deprecated
public MongoURI(String uri)
Deprecated. Replaced by MongoClientURI.MongoClientURI(String)

Creates a MongoURI from a string.

Parameters:
uri - the URI
MongoDB Doc Links

MongoURI

@Deprecated
public MongoURI(MongoClientURI mongoClientURI)
Deprecated. 

Method Detail

getUsername

public String getUsername()
Gets the username

Returns:

getPassword

public char[] getPassword()
Gets the password

Returns:

getHosts

public List<String> getHosts()
Gets the list of hosts

Returns:

getDatabase

public String getDatabase()
Gets the database name

Returns:

getCollection

public String getCollection()
Gets the collection name

Returns:

getCredentials

public MongoCredential getCredentials()
Gets the credentials

Since:
2.11.0

getOptions

public MongoOptions getOptions()
Gets the options. This method will return the same instance of MongoOptions for every call, so it's possible to mutate the returned instance to change the defaults.

Returns:
the mongo options

connect

public Mongo connect()
              throws UnknownHostException
creates a Mongo instance based on the URI

Returns:
a new Mongo instance. There is no caching, so each call will create a new instance, each of which must be closed manually.
Throws:
MongoException
UnknownHostException

connectDB

public DB connectDB()
             throws UnknownHostException
returns the DB object from a newly created Mongo instance based on this URI

Returns:
the database specified in the URI. This will implicitly create a new Mongo instance, which must be closed manually.
Throws:
MongoException
UnknownHostException

connectDB

public DB connectDB(Mongo mongo)
returns the URI's DB object from a given Mongo instance

Parameters:
mongo - the Mongo instance to get the database from.
Returns:
the database specified in this URI

connectCollection

public DBCollection connectCollection(DB db)
returns the URI's Collection from a given DB object

Parameters:
db - the database to get the collection from
Returns:

connectCollection

public DBCollection connectCollection(Mongo mongo)
returns the URI's Collection from a given Mongo instance

Parameters:
mongo - the mongo instance to get the collection from
Returns:
the collection specified in this URI

toString

public String toString()
Overrides:
toString in class Object