MongoDb错误:'当主机未启用日志功能时,无法使用'j'选项'

mfpqipee  于 2022-11-03  发布在  Go
关注(0)|答案(2)|浏览(165)

我在开发中使用mongo很好,当将应用程序部署到测试环境中时,我得到了这个错误:

com.mongodb.MongoCommandException: Command failed with error 2 (BadValue): 'cannot use 'j' option when a host does not have journaling enabled' on server localhost:34653. The full response is {"ok": 0.0, "errmsg": "cannot use 'j' option when a host does not have journaling enabled", "code": 2, "codeName": "BadValue"}

完全卡住跟踪:

Caused by: com.mongodb.MongoCommandException: Command failed with error 2 (BadValue): 'cannot use 'j' option when a host does not have journaling enabled' on server localhost:34653. The full response is {"ok": 0.0, "errmsg": "cannot use 'j' option when a host does not have journaling enabled", "code": 2, "codeName": "BadValue"}
    at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175)
    at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:303)
    at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:259)
    at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:99)
    at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:450)
    at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:72)
    at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:218)
    at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:269)
    at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:131)
    at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:123)
    at com.mongodb.operation.CommandOperationHelper.executeWriteCommand(CommandOperationHelper.java:369)
    at com.mongodb.operation.CommandOperationHelper.executeWriteCommand(CommandOperationHelper.java:360)
    at com.mongodb.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:284)
    at com.mongodb.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:277)
    at com.mongodb.operation.CreateIndexesOperation$1.call(CreateIndexesOperation.java:177)
    at com.mongodb.operation.CreateIndexesOperation$1.call(CreateIndexesOperation.java:172)
    at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:530)
    at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:492)
    at com.mongodb.operation.CreateIndexesOperation.execute(CreateIndexesOperation.java:172)
    at com.mongodb.operation.CreateIndexesOperation.execute(CreateIndexesOperation.java:72)
    at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:206)
    at com.mongodb.client.internal.MongoCollectionImpl.executeCreateIndexes(MongoCollectionImpl.java:886)
    at com.mongodb.client.internal.MongoCollectionImpl.createIndexes(MongoCollectionImpl.java:869)
    at com.mongodb.client.internal.MongoCollectionImpl.createIndexes(MongoCollectionImpl.java:864)
    at com.mongodb.client.internal.MongoCollectionImpl.createIndex(MongoCollectionImpl.java:849)
    at com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase.createRequiredUniqueIndex(MongoSync4RepositoryBase.java:99)
    at com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase.ensureIndex(MongoSync4RepositoryBase.java:58)
    at com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase.initialize(MongoSync4RepositoryBase.java:43)
    at com.github.cloudyrock.mongock.driver.core.driver.ConnectionDriverBase.initialize(ConnectionDriverBase.java:40)
    at com.github.cloudyrock.mongock.runner.core.executor.MigrationExecutor.initializationAndValidation(MigrationExecutor.java:225)
    at com.github.cloudyrock.spring.v5.core.SpringMigrationExecutor.initializationAndValidation(SpringMigrationExecutor.java:31)
    at com.github.cloudyrock.mongock.runner.core.executor.MigrationExecutor.executeMigration(MigrationExecutor.java:63)
    at com.github.cloudyrock.spring.v5.core.SpringMigrationExecutor.executeMigration(SpringMigrationExecutor.java:37)
    at com.github.cloudyrock.mongock.runner.core.executor.MongockRunnerBase.execute(MongockRunnerBase.java:53)
    ... 49 common frames omitted

相关性:
第一个
组态设定:

@Bean
public MongockSpring5.MongockApplicationRunner mongockApplicationRunner(
    ApplicationContext springContext,
    MongoTemplate mongoTemplate) {
    log.debug("Configuring Mongock");
    return MongockSpring5.builder()
        .setDriver(SpringDataMongoV3Driver.withDefaultLock(mongoTemplate))
        // package to scan for migrations
        .addChangeLogsScanPackage("ru.fabit.visor.config.dbmigrations")
        .setSpringContext(springContext)
        .setEnabled(true)
        .buildApplicationRunner();
}

enter image description here
i设置命令:mongod --日记但同样的错误

ne5o7dgx

ne5o7dgx1#

错误很明显,你应该在服务器上启用日志记录。查看here。另一个选择是,不要在writeConcern中配置journal(不推荐)。

92dk7w1h

92dk7w1h2#

这是因为Mongock在默认情况下需要很强的一致性(这是保证一个更改只应用一次的唯一方法),这意味着MongoDB需要启用新闻功能。
但是,正如前面所说,这是默认配置(强烈建议用于生产),但是您可以在特定场景中放松它,例如测试,在测试中您可能希望在内存中设置MongoDB(根据定义,它不允许新闻)。

相关问题