Class MongoTrek


  • public class MongoTrek
    extends Object

    Mongo Trek

    The mongoTrek main class allows an application to provide it's own MongoDatabase instance or MongoDB Connection string to then apply migrations to or report on the migration status of their database schema.
    • Constructor Detail

      • MongoTrek

        public MongoTrek​(String migrationsFile,
                         String uri)
        Create a new MongoTrek instance that will connect to the provided connection string.
        Parameters:
        migrationsFile - The YAML or JSON file containing your MongoDB migrations.
        uri - The Mongo instance connection string
        See Also:
        MongoDB Connection String
      • MongoTrek

        public MongoTrek​(String migrationsFile,
                         com.mongodb.client.MongoDatabase database)
        Create a new MongoTrek instance using a provided MongoDatabase instance. MongoTrek will not close this connection.
        Parameters:
        migrationsFile - The YAML or JSON file containing your MongoDB migrations.
        database - The MongoDatabase instance.
    • Method Detail

      • setSchemaVersionCollection

        public void setSchemaVersionCollection​(String collectionName)
        Change the schema version collection from the default _schema_version
        Parameters:
        collectionName - The schema version collection name
      • status

        public MongoTrekState status​(boolean logStatus)
                              throws MongoTrekFailureException
        Report the status of the migrations and provided commands. Does not apply the migrations.
        Parameters:
        logStatus - flag indicating if the state should be logged
        Returns:
        The trek state
        Throws:
        MongoTrekFailureException - If the status report fails for whatever reason.
      • setClassLoader

        public static void setClassLoader​(ClassLoader classLoader)
        Set the class loader for mongoTrek to use when loading migrations files from resource paths. By default, mongoTrek uses the class loader from MongoTrek.class.getClassLoader(), but sometimes this class loader is not relevant.
        Parameters:
        classLoader - the class loader for mongoTrek to use when loading resources