Class MongoDBUtils


  • public class MongoDBUtils
    extends Object
    Generic operations over MongoDB Driver.
    • Constructor Detail

      • MongoDBUtils

        public MongoDBUtils()
        Generic constructor.
    • Method Detail

      • connect

        public void connect()
                     throws DBException
        Connect to MongoDB Host.
        Throws:
        DBException - DBException
      • disconnect

        public void disconnect()
        Disconnect of MongoDB host.
      • connectToMongoDBDataBase

        public void connectToMongoDBDataBase​(String db)
        Connect to DataBase of MongoDB(If it not exists, it will be created).
        Parameters:
        db - the db name
      • exitsMongoDbDataBase

        public boolean exitsMongoDbDataBase​(String dataBaseName)
        Checks if a database exists in MongoDB.
        Parameters:
        dataBaseName - the data base name
        Returns:
        true if the db exists
      • exitsCollections

        public boolean exitsCollections​(String colName)
        Checks if a collection exists in a MongoDB dataBase.
        Parameters:
        colName - the column name
        Returns:
        boolean boolean
      • getMongoDBCollections

        public Set<String> getMongoDBCollections()
        Get a list of collections of a database.
        Returns:
        Set<String>
      • getMongoDBCollection

        public com.mongodb.DBCollection getMongoDBCollection​(String collectionName)
        Get a MongoDB collection.
        Parameters:
        collectionName - the collection name
        Returns:
        DBCollection mongo db collection
      • createMongoDBCollection

        public void createMongoDBCollection​(String colectionName,
                                            io.cucumber.datatable.DataTable options)
        Create a MongoDB collection.
        Parameters:
        colectionName - the colection name
        options - the options (as datatable object)
      • createMongoDBCollection

        public void createMongoDBCollection​(String colectionName)
        Create a MongoDB collection without options.
        Parameters:
        colectionName - the colection name
      • dropMongoDBDataBase

        public void dropMongoDBDataBase​(String dataBaseName)
        Drop a MongoDB DataBase.
        Parameters:
        dataBaseName - the data base name
      • dropMongoDBCollection

        public void dropMongoDBCollection​(String collectionName)
        Drop a MongoDBCollection.
        Parameters:
        collectionName - the collection name
      • dropAllDataMongoDBCollection

        public void dropAllDataMongoDBCollection​(String collectionName)
        Drop all the data associated to a MongoDB Collection.
        Parameters:
        collectionName - the collection name
      • insertIntoMongoDBCollection

        public void insertIntoMongoDBCollection​(String collection,
                                                io.cucumber.datatable.DataTable table)
        Insert data in a MongoDB Collection.
        Parameters:
        collection - the collection
        table - the table
      • insertDocIntoMongoDBCollection

        public void insertDocIntoMongoDBCollection​(String collection,
                                                   String document)
        Insert document in a MongoDB Collection.
        Parameters:
        collection - the collection
        document - the document
      • readFromMongoDBCollection

        public List<com.mongodb.DBObject> readFromMongoDBCollection​(String collection,
                                                                    io.cucumber.datatable.DataTable table)
        Read data from a MongoDB collection.
        Parameters:
        collection - the collection
        table - the table
        Returns:
        List<DBObjects>