使用 mongock 执行数据迁移,但最终出现以下错误。
摇篮
plugins {
id 'java'
}
group 'fete.bird'
version '0.0.1-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
set('mongockVersion', "4.1.14")
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.3.1.RELEASE'
implementation "com.github.cloudyrock.mongock:mongock-standalone:${mongockVersion}"
implementation "com.github.cloudyrock.mongock:mongodb-sync-v4-driver:${mongockVersion}"
implementation 'org.mongodb:mongodb-driver-sync:4.1.0'
compile project(':Data')
}
独立方法
public class main {
public static void main(String[] args) {
MongockStandalone();
}
private static void MongockStandalone(){
var mongoUri = Configuration.getMongoUri();
MongoClient mongoClient = MongoClients.create("mongodb://127.0.1:27017/");
MongockStandalone.builder()
.setDriver(MongoSync4Driver.withDefaultLock(mongoClient,"FeteBird-Product"))
.addChangeLogsScanPackage("db.migration")
.buildRunner().execute();
}
}
变更日志
@ChangeLog(order = "001")
public class DbChangeLog001 {
@ChangeSet(order = "001", id = "seedProduct", author = "San")
public void seedProduct(MongoDatabase mongoDatabase) {
mongoDatabase.createCollection("Product");
}
}
错误
02:04:52.060 [main] DEBUG org.mongodb.driver.operation - Unable to retry operation listIndexes due to error "com.mongodb.MongoCommandException: Command failed with error 26 (NamespaceNotFound): 'ns does not exist: FeteBird-Product.mongockChangeLog' on server 127.0.1:27017. The full response is {"ok": 0.0, "errmsg": "ns does not exist: FeteBird-Product.mongockChangeLog", "code": 26, "codeName": "NamespaceNotFound"}"
02:04:52.061 [main] DEBUG com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase - Removing residual uniqueKeys for collection [mongockChangeLog]
02:04:52.063 [main] DEBUG org.mongodb.driver.protocol.command - Sending command '{"listIndexes": "mongockChangeLog", "cursor": {}, "$db": "FeteBird-Product", "lsid": {"id": {"$binary": {"base64": "2Ki32rm4RAacZEcl0iUR0A==", "subType": "04"}}}}' with request id 17 to database FeteBird-Product on connection [connectionId{localValue:3, serverValue:20}] to server 127.0.1:27017
02:04:52.069 [main] DEBUG org.mongodb.driver.protocol.command - Execution of command with request id 17 failed to complete successfully in 6.26 ms on connection [connectionId{localValue:3, serverValue:20}] to server 127.0.1:27017
com.mongodb.MongoCommandException: Command failed with error 26 (NamespaceNotFound): 'ns does not exist: FeteBird-Product.mongockChangeLog' on server 127.0.1:27017. The full response is {"ok": 0.0, "errmsg": "ns does not exist: FeteBird-Product.mongockChangeLog", "code": 26, "codeName": "NamespaceNotFound"}
at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175)
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:359)
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:280)
at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:100)
at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:490)
at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:71)
at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:255)
at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:202)
at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:118)
at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:110)
at com.mongodb.internal.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:345)
at com.mongodb.internal.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:336)
at com.mongodb.internal.operation.CommandOperationHelper.executeCommandWithConnection(CommandOperationHelper.java:222)
at com.mongodb.internal.operation.ListIndexesOperation$1.call(ListIndexesOperation.java:171)
at com.mongodb.internal.operation.ListIndexesOperation$1.call(ListIndexesOperation.java:165)
at com.mongodb.internal.operation.OperationHelper.withReadConnectionSource(OperationHelper.java:582)
at com.mongodb.internal.operation.ListIndexesOperation.execute(ListIndexesOperation.java:165)
at com.mongodb.internal.operation.ListIndexesOperation.execute(ListIndexesOperation.java:73)
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:178)
at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135)
at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92)
at com.mongodb.client.internal.MongoIterableImpl.forEach(MongoIterableImpl.java:121)
at com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase.getResidualKeys(MongoSync4RepositoryBase.java:73)
at com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase.cleanResidualUniqueKeys(MongoSync4RepositoryBase.java:66)
at com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase.ensureIndex(MongoSync4RepositoryBase.java:52)
at com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase.initialize(MongoSync4RepositoryBase.java:39)
at io.changock.driver.core.driver.ConnectionDriverBase.initialize(ConnectionDriverBase.java:43)
at io.changock.runner.core.MigrationExecutor.initializationAndValidation(MigrationExecutor.java:189)
at io.changock.runner.core.MigrationExecutor.executeMigration(MigrationExecutor.java:61)
at io.changock.runner.core.ChangockBase.execute(ChangockBase.java:44)
at main.MongockStandalone(main.java:18)
at main.main(main.java:9)