Package org.nuxeo.runtime.mongodb
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MongoDBConnectionHelper.ReadConcernConverter
static class
MongoDBConnectionHelper.ReadPreferenceConverter
static class
MongoDBConnectionHelper.WriteConcernConverter
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.mongodb.client.MongoDatabase
getDatabase(com.mongodb.client.MongoClient mongoClient, String dbname)
protected static SSLContext
getSSLContext(MongoDBConnectionConfig config)
static boolean
hasCollection(com.mongodb.client.MongoDatabase mongoDatabase, String collection)
Check if the collection exists and if it is not emptyprotected static KeyStore
loadKeyStore(String path, String password, String type)
static com.mongodb.client.MongoClient
newMongoClient(String server)
Initialize a connection to the MongoDB serverstatic com.mongodb.client.MongoClient
newMongoClient(MongoDBConnectionConfig config)
Initializes a connection to the MongoDB server.static com.mongodb.client.MongoClient
newMongoClient(MongoDBConnectionConfig config, Consumer<com.mongodb.MongoClientSettings.Builder> settingsConsumer)
Initializes a connection to the MongoDB server.protected static void
populateProperties(MongoDBConnectionConfig config, com.mongodb.MongoClientSettings.Builder settingsBuilder)
Exists to be tested.
-
-
-
Method Detail
-
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 configsettingsConsumer
- 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 databasecollection
- the collection name- Returns:
- true if the collection exists and not empty, false otherwise
-
-