Interface MongoClientFactory

  • All Known Implementing Classes:
    DefaultMongoClientFactory

    @ThreadSafe
    public interface MongoClientFactory
    A factory for creating MongoClients

    A factory should produce MongoClients with the same configuration each time create() is called.

    The creation of a MongoClient is expensive (creating the connection pool and authenticating connections), so MongoClients are automatically cached, using the MongoClientFactory as the key.

    Implementations of the factory can make use of the automatic caching by ensuring the MongoClientFactory.equals() returns true if the MongoClientFactory instances configured with the same relevant MongoConfig values and if the implementation creates MongoClients with the same configuration each time create() is called. Note: Only the MongoConfig values used to create the MongoClient need be compared in the MongoClientFactory.equals() method.

    Note: Implementations must have either a no-args public constructor or a public constructor that takes a single parameter; a MongoConfig instance.

    • Method Detail

      • create

        com.mongodb.client.MongoClient create()
        Returns:
        create a new instance of a MongoClient.