Mongodb无法保持事务状态,因为缺少会话事务集合

时间:2018-10-24 23:32:47

标签: java spring mongodb transactions spring-data-mongodb

我正在将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 

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

1 个答案:

答案 0 :(得分:1)

实际上,该错误很容易解释。似乎出于某种原因,开发环境db中的transactions集合已删除。解决方法很简单:

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