Class MongoDBConnectionHelper

    • 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 config
        settingsConsumer - a consumer of the client settings builder
        Returns:
        the MongoDB client
        Since:
        11.1
      • 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