Class Mongo
- java.lang.Object
-
- com.mongodb.Mongo
-
- Direct Known Subclasses:
MongoClient
@ThreadSafe @Deprecated public class Mongo extends java.lang.Object
Deprecated.Replaced byMongoClient
. Any non-deprecated methods will be moved to MongoClient. The rest will be removed along with this class.A database connection with internal connection pooling. For most applications, you should have one Mongo instance for the entire JVM.
Note: This class has been superseded by
MongoClient
, and may be deprecated in a future release.- See Also:
MongoClient
,ReadPreference
,WriteConcern
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Mongo.Holder
Deprecated.
-
Constructor Summary
Constructors Constructor Description Mongo()
Deprecated.Replaced byMongoClient()
)Mongo(MongoURI uri)
Deprecated.Replaced byMongoClient(MongoClientURI)
Mongo(ServerAddress address)
Deprecated.Replaced byMongoClient(ServerAddress)
Mongo(ServerAddress address, MongoOptions options)
Deprecated.Replaced byMongoClient(ServerAddress, MongoClientOptions)
Mongo(ServerAddress left, ServerAddress right)
Deprecated.Please useMongoClient(java.util.List)
instead.Mongo(ServerAddress left, ServerAddress right, MongoOptions options)
Deprecated.Please useMongoClient(java.util.List, MongoClientOptions)
instead.Mongo(java.lang.String host)
Deprecated.Replaced byMongoClient(String)
Mongo(java.lang.String host, int port)
Deprecated.Replaced byMongoClient(String, int)
Mongo(java.lang.String host, MongoOptions options)
Deprecated.Replaced byMongoClient(String, MongoClientOptions)
Mongo(java.util.List<ServerAddress> seeds)
Deprecated.Replaced byMongoClient(java.util.List)
Mongo(java.util.List<ServerAddress> seeds, MongoOptions options)
Deprecated.Replaced byMongoClient(java.util.List, MongoClientOptions)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addOption(int option)
Deprecated.Add options instead on instances ofDBCursor
void
close()
Deprecated.Closes all resources associated with this instance, in particular any open network connections.void
dropDatabase(java.lang.String dbName)
Deprecated.Drops the database if it exists.CommandResult
fsync(boolean async)
Deprecated.CommandResult
fsyncAndLock()
Deprecated.ServerAddress
getAddress()
Deprecated.java.util.List<ServerAddress>
getAllAddress()
Deprecated.java.lang.String
getConnectPoint()
Deprecated.java.util.List<java.lang.String>
getDatabaseNames()
Deprecated.Replaced withMongoClient.listDatabaseNames()
DB
getDB(java.lang.String dbName)
Deprecated.This method is not currently scheduled for removal, but preferMongoClient.getDatabase(String)
for new code.int
getMaxBsonObjectSize()
Deprecated.MongoOptions
getMongoOptions()
Deprecated.Please useMongoClient
class to connect to server and correspondingMongoClient.getMongoClientOptions()
int
getOptions()
Deprecated.Get options instead from instances ofDBCursor
ReadConcern
getReadConcern()
Deprecated.Gets the read concernReadPreference
getReadPreference()
Deprecated.Gets the default read preferenceReplicaSetStatus
getReplicaSetStatus()
Deprecated.java.util.List<ServerAddress>
getServerAddressList()
Deprecated.java.util.Collection<DB>
getUsedDatabases()
Deprecated.WriteConcern
getWriteConcern()
Deprecated.Gets the write concernboolean
isLocked()
Deprecated.void
resetOptions()
Deprecated.Reset options instead on instances ofDBCursor
void
setOptions(int options)
Deprecated.Set options on instances ofDBCursor
void
setReadPreference(ReadPreference readPreference)
Deprecated.Set the default read preference with eitherMongoClientURI
orMongoClientOptions
void
setWriteConcern(WriteConcern writeConcern)
Deprecated.Set the default write concern with eitherMongoClientURI
orMongoClientOptions
void
slaveOk()
Deprecated.Replaced withReadPreference.secondaryPreferred()
java.lang.String
toString()
Deprecated.DBObject
unlock()
Deprecated.
-
-
-
Constructor Detail
-
Mongo
@Deprecated public Mongo()
Deprecated.Replaced byMongoClient()
)Creates a Mongo instance based on a (single) mongodb node (localhost, default port)- Throws:
MongoException
- if there's a failure
-
Mongo
@Deprecated public Mongo(java.lang.String host)
Deprecated.Replaced byMongoClient(String)
Creates a Mongo instance based on a (single) mongodb node (default port)- Parameters:
host
- server to connect to
-
Mongo
@Deprecated public Mongo(java.lang.String host, MongoOptions options)
Deprecated.Replaced byMongoClient(String, MongoClientOptions)
Creates a Mongo instance based on a (single) mongodb node (default port)- Parameters:
host
- server to connect tooptions
- default query options
-
Mongo
@Deprecated public Mongo(java.lang.String host, int port)
Deprecated.Replaced byMongoClient(String, int)
Creates a Mongo instance based on a (single) mongodb node- Parameters:
host
- the host address of the databaseport
- the port on which the database is running
-
Mongo
@Deprecated public Mongo(ServerAddress address)
Deprecated.Replaced byMongoClient(ServerAddress)
Creates a Mongo instance based on a (single) mongodb node- Parameters:
address
- the database address- See Also:
ServerAddress
-
Mongo
@Deprecated public Mongo(ServerAddress address, MongoOptions options)
Deprecated.Replaced byMongoClient(ServerAddress, MongoClientOptions)
Creates a Mongo instance based on a (single) mongo node using a given ServerAddress- Parameters:
address
- the database addressoptions
- default query options- See Also:
ServerAddress
-
Mongo
@Deprecated public Mongo(ServerAddress left, ServerAddress right)
Deprecated.Please useMongoClient(java.util.List)
instead.Creates a Mongo in paired mode.
This will also work for a replica set and will find all members (the master will be used by default).
- Parameters:
left
- left side of the pairright
- right side of the pair- See Also:
ServerAddress
-
Mongo
@Deprecated public Mongo(ServerAddress left, ServerAddress right, MongoOptions options)
Deprecated.Please useMongoClient(java.util.List, MongoClientOptions)
instead.Creates a Mongo connection in paired mode.
This will also work for a replica set and will find all members (the master will be used by default).
- Parameters:
left
- left side of the pairright
- right side of the pairoptions
- the optional settings for the Mongo instance- See Also:
ServerAddress
-
Mongo
@Deprecated public Mongo(java.util.List<ServerAddress> seeds)
Deprecated.Replaced byMongoClient(java.util.List)
Creates an instance based on a list of replica set members or mongos servers. For a replica set it will discover all members. For a list with a single seed, the driver will still discover all members of the replica set. For a direct connection to a replica set member, with no discovery, use the
Mongo(ServerAddress)
constructor instead.When there is more than one server to choose from based on the type of request (read or write) and the read preference (if it's a read request), the driver will randomly select a server to send a request. This applies to both replica sets and sharded clusters. The servers to randomly select from are further limited by the local threshold. See
MongoClientOptions.getLocalThreshold()
- Parameters:
seeds
- Put as many servers as you can in the list and the system will figure out the rest. This can either be a list of mongod servers in the same replica set or a list of mongos servers in the same sharded cluster.- See Also:
MongoClientOptions.getLocalThreshold()
-
Mongo
@Deprecated public Mongo(java.util.List<ServerAddress> seeds, MongoOptions options)
Deprecated.Replaced byMongoClient(java.util.List, MongoClientOptions)
Creates an instance based on a list of replica set members or mongos servers. For a replica set it will discover all members. For a list with a single seed, the driver will still discover all members of the replica set. For a direct connection to a replica set member, with no discovery, use the
Mongo(ServerAddress, MongoClientOptions)
constructor instead.When there is more than one server to choose from based on the type of request (read or write) and the read preference (if it's a read request), the driver will randomly select a server to send a request. This applies to both replica sets and sharded clusters. The servers to randomly select from are further limited by the local threshold. See
MongoClientOptions.getLocalThreshold()
- Parameters:
seeds
- Put as many servers as you can in the list and the system will figure out the rest. This can either be a list of mongod servers in the same replica set or a list of mongos servers in the same sharded cluster.options
- the options- See Also:
MongoClientOptions.getLocalThreshold()
-
Mongo
@Deprecated public Mongo(MongoURI uri)
Deprecated.Replaced byMongoClient(MongoClientURI)
Creates a Mongo described by a URI. If only one address is used it will only connect to that node, otherwise it will discover all nodes. If the URI contains database credentials, the database will be authenticated lazily on first use with those credentials.
Examples:
- mongodb://localhost
- mongodb://fred:foobar@localhost/
- Parameters:
uri
- URI to connect to, optionally containing additional information like credentials- Throws:
MongoException
- if there's a failure- See Also:
MongoURI
-
-
Method Detail
-
setWriteConcern
@Deprecated public void setWriteConcern(WriteConcern writeConcern)
Deprecated.Set the default write concern with eitherMongoClientURI
orMongoClientOptions
Sets the default write concern to use for write operations executed on anyDBCollection
created indirectly from this instance, via aDB
instance created fromgetDB(String)
.Note that changes to the default write concern made via this method will NOT affect the write concern of
MongoDatabase
instances created viaMongoClient.getDatabase(String)
- Parameters:
writeConcern
- write concern to use
-
getWriteConcern
public WriteConcern getWriteConcern()
Deprecated.Gets the write concern- Returns:
- the write concern
-
getReadConcern
public ReadConcern getReadConcern()
Deprecated.Gets the read concern- Returns:
- the read concern
-
setReadPreference
@Deprecated public void setReadPreference(ReadPreference readPreference)
Deprecated.Set the default read preference with eitherMongoClientURI
orMongoClientOptions
Sets the default read preference to use for reads operations executed on anyDBCollection
created indirectly from this instance, via aDB
instance created fromgetDB(String)
.Note that changes to the default read preference made via this method will NOT affect the read preference of
MongoDatabase
instances created viaMongoClient.getDatabase(String)
- Parameters:
readPreference
- Read Preference to use
-
getReadPreference
public ReadPreference getReadPreference()
Deprecated.Gets the default read preference- Returns:
- the default read preference
-
getAllAddress
@Deprecated public java.util.List<ServerAddress> getAllAddress()
Deprecated.Gets a list of all server addresses used when this Mongo was created- Returns:
- list of server addresses
- Throws:
MongoException
- if there's a failure
-
getServerAddressList
@Deprecated public java.util.List<ServerAddress> getServerAddressList()
Deprecated.Gets the list of server addresses currently seen by this client. This includes addresses auto-discovered from a replica set.- Returns:
- list of server addresses
- Throws:
MongoException
- if there's a failure
-
getAddress
@Deprecated @Nullable public ServerAddress getAddress()
Deprecated.Gets the address of the current master- Returns:
- the address
-
getMongoOptions
@Deprecated public MongoOptions getMongoOptions()
Deprecated.Please useMongoClient
class to connect to server and correspondingMongoClient.getMongoClientOptions()
Returns the mongo options.
Changes to
MongoOptions
that are done after connection are not reflected.- Returns:
- the mongo options
-
getReplicaSetStatus
@Deprecated @Nullable public ReplicaSetStatus getReplicaSetStatus()
Deprecated.Get the status of the replica set cluster.- Returns:
- replica set status information
-
getDatabaseNames
@Deprecated public java.util.List<java.lang.String> getDatabaseNames()
Deprecated.Replaced withMongoClient.listDatabaseNames()
Gets a list of the names of all databases on the connected server.- Returns:
- list of database names
- Throws:
MongoException
- if the operation fails
-
getDB
@Deprecated public DB getDB(java.lang.String dbName)
Deprecated.This method is not currently scheduled for removal, but preferMongoClient.getDatabase(String)
for new code. Note thatDB
andMongoDatabase
can be used together in the same application, whith the sameMongoClient
instance.Gets a database object. Users should useMongoClient.getDatabase(String)
instead.The
DB
class has been superseded byMongoDatabase
. The deprecation of this method effectively deprecates theDB
,DBCollection
, andDBCursor
classes, among others; but in order to give users time to migrate to the new API without experiencing a huge number of compiler warnings, those classes have not yet been formally deprecated.- Parameters:
dbName
- the name of the database to retrieve- Returns:
- a DB representing the specified database
- Throws:
java.lang.IllegalArgumentException
- if the name is invalid- See Also:
MongoNamespace.checkDatabaseNameValidity(String)
-
getUsedDatabases
@Deprecated public java.util.Collection<DB> getUsedDatabases()
Deprecated.Returns the list of databases used by the driver since this Mongo instance was created. This may include DBs that exist in the client but not yet on the server.- Returns:
- a collection of database objects
-
dropDatabase
public void dropDatabase(java.lang.String dbName)
Deprecated.Drops the database if it exists.- Parameters:
dbName
- name of database to drop- Throws:
MongoException
- if the operation fails
-
close
public void close()
Deprecated.Closes all resources associated with this instance, in particular any open network connections. Once called, this instance and any databases obtained from it can no longer be used.
-
slaveOk
@Deprecated public void slaveOk()
Deprecated.Replaced withReadPreference.secondaryPreferred()
Makes it possible to run read queries on secondary nodes- See Also:
ReadPreference.secondaryPreferred()
-
setOptions
@Deprecated public void setOptions(int options)
Deprecated.Set options on instances ofDBCursor
Set the default query options for reads operations executed on anyDBCollection
created indirectly from this instance, via aDB
instance created fromgetDB(String)
.Note that changes to query options made via this method will NOT affect
MongoDatabase
instances created viaMongoClient.getDatabase(String)
- Parameters:
options
- value to be set
-
resetOptions
@Deprecated public void resetOptions()
Deprecated.Reset options instead on instances ofDBCursor
Reset the default query options for reads operations executed on anyDBCollection
created indirectly from this instance, via aDB
instance created fromgetDB(String)
.
-
addOption
@Deprecated public void addOption(int option)
Deprecated.Add options instead on instances ofDBCursor
Add the default query option for reads operations executed on anyDBCollection
created indirectly from this instance, via aDB
instance created fromgetDB(String)
.Note that changes to query options made via this method will NOT affect
MongoDatabase
instances created viaMongoClient.getDatabase(String)
- Parameters:
option
- value to be added to current options
-
getOptions
@Deprecated public int getOptions()
Deprecated.Get options instead from instances ofDBCursor
Gets the default query options for reads operations executed on anyDBCollection
created indirectly from this instance, via aDB
instance created fromgetDB(String)
.- Returns:
- an int representing the options to be used by queries
-
fsync
@Deprecated public CommandResult fsync(boolean async)
Deprecated.Forces the master server to fsync the RAM data to disk This is done automatically by the server at intervals, but can be forced for better reliability.- Parameters:
async
- if true, the fsync will be done asynchronously on the server.- Returns:
- result of the command execution
- Throws:
MongoException
- if there's a failure
-
fsyncAndLock
@Deprecated public CommandResult fsyncAndLock()
Deprecated.Forces the master server to fsync the RAM data to disk, then lock all writes. The database will be read-only after this command returns.- Returns:
- result of the command execution
- Throws:
MongoException
- if there's a failure
-
unlock
@Deprecated public DBObject unlock()
Deprecated.Unlocks the database, allowing the write operations to go through. This command may be asynchronous on the server, which means there may be a small delay before the database becomes writable.- Returns:
DBObject
in the following form{"ok": 1,"info": "unlock completed"}
- Throws:
MongoException
- if there's a failure
-
isLocked
@Deprecated public boolean isLocked()
Deprecated.Returns true if the database is locked (read-only), false otherwise.- Returns:
- result of the command execution
- Throws:
MongoException
- if the operation fails
-
toString
public java.lang.String toString()
Deprecated.- Overrides:
toString
in classjava.lang.Object
-
getMaxBsonObjectSize
@Deprecated public int getMaxBsonObjectSize()
Deprecated.Gets the maximum size for a BSON object supported by the current master server. Note that this value may change over time depending on which server is master.- Returns:
- the maximum size, or 0 if not obtained from servers yet.
- Throws:
MongoException
- if there's a failure
-
getConnectPoint
@Deprecated @Nullable public java.lang.String getConnectPoint()
Deprecated.Gets aString
representation of current connection point, i.e. master.- Returns:
- server address in a host:port form
-
-