java - Mongodb 无法持久化事务状态,因为 session 事务集合丢失

标签 java spring mongodb transactions spring-data-mongodb

我正在使用带有 Spring Boot 的 Mongodb 4 2.1.0-M4

以下代码在我的计算机上本地运行,但在开发环境中失败:

@Transactional
public void registerNewUser(UserRegistrationForm registrationForm)
        throws IllegalArgumentException {

    validator.validate(registrationForm);

    User user = new User();
    user.setEmail(registrationForm.email);
    user.setPassword(encoder.encode(registrationForm.password));
    user.setEnabled(false);
    user.setGroups(Sets.newHashSet(ClientRoles.USER));

    User saved = userRepository.save(user);

    registrationService.sendInvitation(user.getEmail());
}

出现以下错误:

com.mongodb.MongoCommandException: Command failed with error 40527 (Location40527): 'Unable to persist transaction state because the session transaction collection is missing. This indicates that the config.transactions collection has been manually deleted.' on server mongodb-1-servers-vm-0:27017. The full response is { "operationTime" : { "$timestamp" : { "t" : 1540422989, "i" : 1 } }, "ok" : 0.0, "errmsg" : "Unable to persist transaction state because the session transaction collection is missing. This indicates that the config.transactions collection has been manually deleted.", "code" : 40527, "codeName" : "Location40527", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1540422994, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } at 

我不知道应该尝试调试什么,或者尝试什么,两个数据库都是相同的版本并且已初始化副本集。任何帮助表示赞赏。

最佳答案

实际上,这个错误是不言自明的。似乎由于某种原因,开发环境数据库中的 transactions 集合已被删除。修复方法很简单:

use config
db.createCollection("transactions",{})

关于java - Mongodb 无法持久化事务状态,因为 session 事务集合丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52979301/

相关文章:

Java 集合<对象> 或集合<?>

java - Spring 文件上传 - 'Required request part is not present'

java.lang.unsupportedoperationexception 应用程序必须提供 JDBC 连接

JavaScript Json 解析器

javascript - MongoDb - 重新加入分割的 MapReduce 任务

java - 如何使用apache-poi获取文件的全部内容?

java - 为什么我的 android volley 的 http post 请求会抛出错误(localhost)?

java - 通过反射检索的对象的同步

java - 不使用 web.xml 加载应用程序上下文

mongodb - 设计具有多对多关系的 mongodb 模式