Package com.mongodb

Class Mongo

  • Direct Known Subclasses:
    MongoClient

    @ThreadSafe
    @Deprecated
    public class Mongo
    extends java.lang.Object
    Deprecated.
    Replaced by MongoClient. 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
    • 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​(java.lang.String host)
        Deprecated.
        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)
        Creates a Mongo instance based on a (single) mongodb node (default port)
        Parameters:
        host - server to connect to
        options - default query options
      • Mongo

        @Deprecated
        public Mongo​(java.lang.String host,
                     int port)
        Deprecated.
        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​(ServerAddress left,
                     ServerAddress right)
        Deprecated.
        Please use MongoClient(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 pair
        right - right side of the pair
        See Also:
        ServerAddress
      • Mongo

        @Deprecated
        public Mongo​(java.util.List<ServerAddress> seeds)
        Deprecated.

        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)

        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.

        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 either MongoClientURI or MongoClientOptions
        Sets the default write concern to use for write operations executed on any DBCollection created indirectly from this instance, via a DB instance created from getDB(String).

        Note that changes to the default write concern made via this method will NOT affect the write concern of MongoDatabase instances created via MongoClient.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 either MongoClientURI or MongoClientOptions
        Sets the default read preference to use for reads operations executed on any DBCollection created indirectly from this instance, via a DB instance created from getDB(String).

        Note that changes to the default read preference made via this method will NOT affect the read preference of MongoDatabase instances created via MongoClient.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 use MongoClient class to connect to server and corresponding MongoClient.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.
        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 prefer MongoClient.getDatabase(String) for new code. Note that DB and MongoDatabase can be used together in the same application, whith the same MongoClient instance.
        Gets a database object. Users should use MongoClient.getDatabase(String) instead.

        The DB class has been superseded by MongoDatabase. The deprecation of this method effectively deprecates the DB, DBCollection, and DBCursor 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 with ReadPreference.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 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
      • 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 class java.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 a String representation of current connection point, i.e. master.
        Returns:
        server address in a host:port form