Package org.nuxeo.runtime.mongodb
Class MongoDBConnectionHelper
java.lang.Object
org.nuxeo.runtime.mongodb.MongoDBConnectionHelper
Helper for connection to the MongoDB server
- Since:
- 9.1
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
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 Details
-
newMongoClient
Initialize a connection to the MongoDB server- Parameters:
server
- the server url- Returns:
- the MongoDB client
-
newMongoClient
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
-
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
-