Class MongoDBConnectionHelper

java.lang.Object
org.nuxeo.runtime.mongodb.MongoDBConnectionHelper

public class MongoDBConnectionHelper extends Object
Helper for connection to the MongoDB server
Since:
9.1
  • Method Details

    • newMongoClient

      public static com.mongodb.client.MongoClient newMongoClient(String server)
      Initialize a connection to the MongoDB server
      Parameters:
      server - the server url
      Returns:
      the MongoDB client
    • newMongoClient

      public static com.mongodb.client.MongoClient newMongoClient(MongoDBConnectionConfig config)
      Initializes a connection to the MongoDB server.
      Parameters:
      config - the MongoDB connection config
      Returns:
      the MongoDB client
      Since:
      10.3
    • newMongoClient

      public static com.mongodb.client.MongoClient newMongoClient(MongoDBConnectionConfig config, Consumer<com.mongodb.MongoClientSettings.Builder> settingsConsumer)
      Initializes a connection to the MongoDB server.
      Parameters:
      config - the MongoDB connection config
      settingsConsumer - a consumer of the client settings builder
      Returns:
      the MongoDB client
      Since:
      11.1
    • populateProperties

      protected static void populateProperties(MongoDBConnectionConfig config, com.mongodb.MongoClientSettings.Builder settingsBuilder)
      Exists to be tested.
      Since:
      11.4
    • getSSLContext

      protected static SSLContext getSSLContext(MongoDBConnectionConfig config)
    • loadKeyStore

      protected static KeyStore loadKeyStore(String path, String password, String type) throws GeneralSecurityException, IOException
      Throws:
      GeneralSecurityException
      IOException
    • getDatabase

      public static com.mongodb.client.MongoDatabase getDatabase(com.mongodb.client.MongoClient mongoClient, String dbname)
      Returns:
      a database representing the specified database
    • hasCollection

      public static boolean hasCollection(com.mongodb.client.MongoDatabase mongoDatabase, String collection)
      Check if the collection exists and if it is not empty
      Parameters:
      mongoDatabase - the Mongo database
      collection - the collection name
      Returns:
      true if the collection exists and not empty, false otherwise