public class MongoTrek extends Object
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.
public class MyApplication {
public void start(){
try {
MongoTrek trek = new MongoTrek("mongodb://root:password@localhost:27017/my_application");
trek.setSchemaVersionCollection("_schema_version_my_application");
MongoTrekState state = trek.migrate("mongodb/trek.yml");
LOGGER.info("Completed migrations to version " + state.getCurrentVersion());
} catch (MongoMigrationFailureException e) {
LOGGER.error("Error migrating database, e);
}
}
}
| Constructor and Description |
|---|
MongoTrek(String migrationsFile,
com.mongodb.client.MongoDatabase database)
Create a new MongoTrek instance using a provided
MongoDatabase instance. |
MongoTrek(String migrationsFile,
String uri)
Create a new MongoTrek instance that will connect to the provided connection string.
|
| Modifier and Type | Method and Description |
|---|---|
MongoTrekState |
migrate()
Migrate the Mongo database using the provided collection of commands.
|
void |
setSchemaVersionCollection(String collectionName)
Change the schema version collection from the default
_schema_version |
MongoTrekState |
status()
Report the status of the migrations and provided commands.
|
MongoTrekState |
status(boolean logStatus)
Report the status of the migrations and provided commands.
|
public MongoTrek(String migrationsFile, String uri)
Create a new MongoTrek instance that will connect to the provided connection string.
migrationsFile - The YAML or JSON file containing your MongoDB migrations.uri - The Mongo instance connection stringConnection String](https://docs.mongodb.com/manual/reference/connection-string/)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.
migrationsFile - The YAML or JSON file containing your MongoDB migrations.database - The MongoDatabase instance.public void setSchemaVersionCollection(String collectionName)
Change the schema version collection from the default _schema_version
collectionName - The schema version collection namepublic MongoTrekState migrate() throws MongoTrekFailureException
Migrate the Mongo database using the provided collection of commands. Will not apply versions already applied successfully.
MongoTrekFailureException - If the migration fails for whatever reason.public MongoTrekState status() throws MongoTrekFailureException
Report the status of the migrations and provided commands. Does not apply the migrations.
By default, this method will not log status to the logger. Refer to the status(boolean) method.
MongoTrekFailureException - If the status report fails for whatever reason.public MongoTrekState status(boolean logStatus) throws MongoTrekFailureException
Report the status of the migrations and provided commands. Does not apply the migrations.
logStatus - flag indicating if the state should be loggedMongoTrekFailureException - If the status report fails for whatever reason.Copyright © 2018. All Rights Reserved.