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(com.mongodb.client.MongoDatabase database)
Create a new MongoTrek instance using a provided
MongoDatabase instance. |
MongoTrek(String uri)
Create a new MongoTrek instance that will connect to the provided connection string.
|
| Modifier and Type | Method and Description |
|---|---|
MongoTrekState |
migrate(String migrationsFile)
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(String migrationsFile)
Report the status of the migrations and provided commands.
|
public MongoTrek(String uri)
Create a new MongoTrek instance that will connect to the provided connection string.
uri - The Mongo instance connection stringConnection String](https://docs.mongodb.com/manual/reference/connection-string/)public MongoTrek(com.mongodb.client.MongoDatabase database)
Create a new MongoTrek instance using a provided MongoDatabase instance. MongoTrek will not close this connection.
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(String migrationsFile) throws MongoTrekFailureException
Migrate the Mongo database using the provided collection of commands. Will not apply versions already applied successfully.
migrationsFile - The migrations file to apply (should be on the classpath)MongoTrekFailureException - If the migration fails for whatever reason.public MongoTrekState status(String migrationsFile) throws MongoTrekFailureException
Report the status of the migrations and provided commands. Does not apply the migrations.
migrationsFile - The migrations file to apply (should be on the classpath)MongoTrekFailureException - If the status report fails for whatever reason.Copyright © 2016. All Rights Reserved.