Class MongoClients


  • public final class MongoClients
    extends Object
    A factory for MongoClient instances. Use of this class is now the recommended way to connect to MongoDB via the Java driver.
    Since:
    3.7
    See Also:
    MongoClient
    • Method Detail

      • create

        public static MongoClient create()
        Creates a new client with the default connection string "mongodb://localhost".
        Returns:
        the client
      • create

        public static MongoClient create(MongoClientSettings settings)
        Create a new client with the given client settings.
        Parameters:
        settings - the settings
        Returns:
        the client
      • create

        public static MongoClient create(ConnectionString connectionString,
                                         @Nullable
                                         MongoDriverInformation mongoDriverInformation)
        Create a new client with the given connection string.

        Note: Intended for driver and library authors to associate extra driver metadata with the connections.

        Parameters:
        connectionString - the settings
        mongoDriverInformation - any driver information to associate with the MongoClient
        Returns:
        the client
        Throws:
        IllegalArgumentException - if the connection string's stream type is not one of "netty" or "nio2"
        See Also:
        create(ConnectionString)
      • create

        public static MongoClient create(MongoClientSettings settings,
                                         @Nullable
                                         MongoDriverInformation mongoDriverInformation)
        Creates a new client with the given client settings.

        Note: Intended for driver and library authors to associate extra driver metadata with the connections.

        Parameters:
        settings - the settings
        mongoDriverInformation - any driver information to associate with the MongoClient
        Returns:
        the client