Package com.mongodb

Class Mongo

  • Direct Known Subclasses:
    MongoClient

    Deprecated. 
    Replaced by MongoClient. Any non-deprecated methods will be moved to MongoClient. The rest will be removed along with this class.

    @ThreadSafe
    @Deprecated
    public class Mongo
    extends Object

    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
    • Constructor Detail

      • Mongo

        @Deprecated
        public Mongo​()
        Deprecated. Replaced by MongoClient())
        Creates a Mongo instance based on a (single) mongodb node (localhost, default port)
        Throws:
        MongoException - if there's a failure
      • Mongo

        @Deprecated
        public Mongo​(String host)
        Deprecated. Replaced by MongoClient(String)
        Creates a Mongo instance based on a (single) mongodb node (default port)
        Parameters:
        host - server to connect to
      • Mongo

        @Deprecated
        public Mongo​(String host,
                     int port)
        Deprecated. Replaced by MongoClient(String, int)
        Creates a Mongo instance based on a (single) mongodb node
        Parameters:
        host - the host address of the database
        port - the port on which the database is running
      • Mongo

        @Deprecated
        public Mongo​(List<ServerAddress> seeds)
        Deprecated. Replaced by MongoClient(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​(List<ServerAddress> seeds,
                     MongoOptions options)

        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 by MongoClient(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
        MongoDB documentation
        Connection String URI Format
    • Method Detail

      • 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
      • getReadPreference

        public ReadPreference getReadPreference​()
        Deprecated. 
        Gets the default read preference
        Returns:
        the default read preference
      • getAllAddress

        @Deprecated
        public 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 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
      • getReplicaSetStatus

        @Deprecated
        @Nullable
        public ReplicaSetStatus getReplicaSetStatus​()
        Deprecated. 
        Get the status of the replica set cluster.
        Returns:
        replica set status information
      • getUsedDatabases

        @Deprecated
        public 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​(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.
      • setOptions

        @Deprecated
        public void setOptions​(int options)
        Deprecated. Set options on instances of DBCursor
        Set the default query options for reads operations executed on any DBCollection created indirectly from this instance, via a DB instance created from getDB(String).

        Note that changes to query options made via this method will NOT affect MongoDatabase instances created via MongoClient.getDatabase(String)

        Parameters:
        options - value to be set
      • resetOptions

        @Deprecated
        public void resetOptions​()
        Deprecated. Reset options instead on instances of DBCursor
        Reset the default query options for reads operations executed on any DBCollection created indirectly from this instance, via a DB instance created from getDB(String).
      • addOption

        @Deprecated
        public void addOption​(int option)
        Deprecated. Add options instead on instances of DBCursor
        Add the default query option for reads operations executed on any DBCollection created indirectly from this instance, via a DB instance created from getDB(String).

        Note that changes to query options made via this method will NOT affect MongoDatabase instances created via MongoClient.getDatabase(String)

        Parameters:
        option - value to be added to current options
      • getOptions

        @Deprecated
        public int getOptions​()
        Deprecated. Get options instead from instances of DBCursor
        Gets the default query options for reads operations executed on any DBCollection created indirectly from this instance, via a DB instance created from getDB(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
        MongoDB documentation
        fsync command
      • 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
        MongoDB documentation
        fsync command
      • 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
        MongoDB documentation
        fsync command
      • 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
        MongoDB documentation
        fsync command
      • 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 String getConnectPoint​()
        Deprecated. 
        Gets a String representation of current connection point, i.e. master.
        Returns:
        server address in a host:port form