Class MongoClients

java.lang.Object
com.mongodb.client.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:
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new client with the default connection string "mongodb://localhost".
    create(com.mongodb.ConnectionString connectionString)
    Create a new client with the given connection string.
    create(com.mongodb.ConnectionString connectionString, com.mongodb.MongoDriverInformation mongoDriverInformation)
    Create a new client with the given connection string.
    create(com.mongodb.MongoClientSettings settings)
    Create a new client with the given client settings.
    create(com.mongodb.MongoClientSettings settings, com.mongodb.MongoDriverInformation mongoDriverInformation)
    Creates a new client with the given client settings.
    create(String connectionString)
    Create a new client with the given connection string as if by a call to create(ConnectionString).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

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

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

      public static MongoClient create(String connectionString)
      Create a new client with the given connection string as if by a call to create(ConnectionString).
      Parameters:
      connectionString - the connection
      Returns:
      the client
      See Also:
    • create

      public static MongoClient create(com.mongodb.ConnectionString connectionString)
      Create a new client with the given connection string.

      For each of the settings classed configurable via MongoClientSettings, the connection string is applied by calling the applyConnectionString method on an instance of setting's builder class, building the setting, and adding it to an instance of MongoClientSettings.Builder.

      Parameters:
      connectionString - the settings
      Returns:
      the client
      See Also:
      • MongoClientSettings.Builder.applyConnectionString(ConnectionString)
    • create

      public static MongoClient create(com.mongodb.ConnectionString connectionString, @Nullable com.mongodb.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
      See Also:
    • create

      public static MongoClient create(com.mongodb.MongoClientSettings settings, @Nullable com.mongodb.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